model
```
class Content extends ActiveRecord
{
	public static $templates = ['item', 'artwork', 'article', 'exhibition', 'artist', 'catalog'];
	
	protected static array $allowedTemplatesByType = [
		'post' => ['article', 'artwork', 'exhibition', 'artist', 'catalog'],
		'product' => ['artwork', 'exhibition', 'item', 'catalog'],
		//ContentCategory::TYPE_CATALOG => [],// no templates or as needed
	];
	
	protected static array $typeMap = [
		'post' => ContentCategory::TYPE_POST,// Int 1
		'product' => ContentCategory::TYPE_PRODUCT,// Int 2
		// 'catalog' => ContentCategory::TYPE_CATALOG,
	];
	
	protected static array $typeLabels = [
		ContentCategory::TYPE_POST => 'post',
		ContentCategory::TYPE_PRODUCT => 'product',
		// ...
	];
	
	public static function tableName(): string
	{
		return '{{%content}}';
	}
	
	public function scenarios(): array
	{
		$baseAttributes = [
			'type', 'template', 'category_id', 'category_title', 'status', 'title', 
			'slug', 'body', 'image_header', 'meta_description', 'meta_keywords',
			
			/**
			* Handled by TimestampBehavior
			'created_at', 'updated_at',//*/
			
			/**
			* Handled by BlameableBehavior
			'created_by', 'updated_by',//*/
		];
		
		// Add purchaseOptionsArray here because it's used virtually
		$baseAttributes[] = 'purchaseOptionsArray';
		
		return [
			ContentCategory::TYPE_POST => $baseAttributes,
			ContentCategory::TYPE_PRODUCT => array_merge($baseAttributes, [
				'artist', 'dimensions', 'medium', 'year', 
				'price', 'purchase_options', 'hide_price', 'quantity', 
				'product_image_one', 'product_image_two', 'product_image_three',
			]),
			//ContentCategory::TYPE_CATALOG => $baseAttributes,
			
			'post_artwork' => array_merge($baseAttributes, [
				'artist', 'dimensions', 'medium', 'year', 'quantity', 
				'product_image_one', 'product_image_two', 'product_image_three',
			]),
			'post_article' => $baseAttributes,
			'post_exhibition' => array_merge($baseAttributes, [
				'start_date', 'end_date',
			]),
			'post_catalog' => $baseAttributes,
			'product_artwork' => array_merge($baseAttributes, [
				'artist', 'dimensions', 'medium', 'year',
				'price', 'purchase_options', 'hide_price', 'quantity', 
				'product_image_one', 'product_image_two', 'product_image_three',
			]),
			'product_item' => array_merge($baseAttributes, [
				'artist',
				'price', 'purchase_options', 'quantity', 
				'product_image_one', 'product_image_two', 'product_image_three',
			]),
			'product_catalog' => $baseAttributes,
			'default' => $baseAttributes,
		];
	}
	
	public function rules(): array
	{
		return [
			/**
			* Required attributes
			*/
			[['type', 'template', 'category_id', 'status', 'title', 'body', 'meta_description'], 'required'],
			[['artist', 'price', 'purchase_options', 'quantity', 'product_image_one'], 'required', 'on' => ['product_artwork']],
			[['price', 'quantity', 'purchase_options', 'product_image_one'], 'required', 'on' => ['product_item']],
			[['start_date', 'end_date'], 'required', 'on' => ['post_exhibition']],
			
			/**
			* String attributes
			*/
			[['body', 'template', 'meta_description', 'meta_keywords', 'category_title'], 'string'],
			[['title', 'artist', 'dimensions', 'medium', 'category_title', 'meta_keywords', 'slug'], 'string', 'max' => 255],
			[['image_header', 'product_image_one', 'product_image_two', 'product_image_three'], 'string', 'max' => 2000],
			['meta_description', 'string', 'max' => $this->_contentSummaryLength],
			['template', 'string', 'max' => 50],
			
			['hide_price', 'boolean'],
			['hide_price', 'default', 'value' => false],
			
			['purchaseOptionsArray', 'safe'],
			
			['status', 'default', 'value' => self::STATUS_DRAFT],
			// Valid status values by type, conditional on type
			['status', 'in', 'range' => [self::STATUS_DRAFT, self::STATUS_PUBLISH], 
				'when' => fn($model) => $model->type === ContentCategory::TYPE_POST,
			],
			['status', 'in', 'range' => [self::STATUS_DRAFT, self::STATUS_PUBLISH, self::STATUS_SOLDOUT], 
				'when' => fn($model) => $model->type === ContentCategory::TYPE_PRODUCT,
			],
			// Default 'type' and 'template' values by type
			['type', 'default', 'value' => ContentCategory::TYPE_POST],
			['template', 'default', 'value' => 'article', 
				'when' => fn($model) => $model->type === ContentCategory::TYPE_POST],
			['template', 'default', 'value' => 'item', 
				'when' => fn($model) => $model->type === ContentCategory::TYPE_PRODUCT],
			// purchase_options default bitmask
			['purchase_options', 'default', 'value' => self::PURCHASE_OPTIONS_CART | self::PURCHASE_OPTIONS_INQUIRE],
			
			['price', 'match',
				'pattern' => '/^\d+(\.\d{1,2})?$/',
				'message' => \Yii::t('app', 'The price must be a valid decimal number with up to two decimal places.'),
				'skipOnEmpty' => true,// skip validation when price is empty
				'on' => ['product_artwork', 'product_item'],
			],
			// Numeric range validation on price
			['price', 'number',
				'min' => 2.00,
				'max' => 5000000.00,
				'message' => \Yii::t('app', 'The price must be a valid number between $2.00 and $5,000,000.00.'),
				'skipOnEmpty' => true,// skip validation when price is empty
				'on' => ['product_artwork', 'product_item'],
			],
			['quantity', 'integer', 'min' => 0, 'skipOnEmpty' => true, 'on' => ['product_artwork', 'product_item'],],
			/* TODO URL validation for product images
			[['product_image_one', 'product_image_two', 'product_image_three'], 'url',
				'skipOnEmpty' => true,// skip validation when price is empty
				'message' => \Yii::t('app', 'Product Image URL is not valid.'),
				'on' => ['product_artwork', 'product_item'],
				'allowLocal' => true,
			],//*/
			
			[['template'], 'validateTemplateByType'],
			[['meta_description'], 'summaryLength'],
			//[['price'], 'validateDecimalPlaces'],
			//[['price'], 'validateMoney', 'skipOnError' => true],// TODO
			[['purchaseOptionsArray'], 'validatePurchaseOptions'],// Handled by getter and setter
			[['product_image_one', 'product_image_two', 'product_image_three'], 
				'validateProductImageUrl', /*'skipOnEmpty' => true,*/
				'message' => \Yii::t('app', 'Product Image URL is not valid.'), 
				'on' => ['product_artwork', 'product_item']
			],
			
			['category_id', 'exist', 'skipOnEmpty' => false, 'skipOnError' => true, 'targetClass' => ContentCategory::class, 
				'targetAttribute' => ['category_id' => 'id'], 'message' => \Yii::t('app', 'Please select a valid category.')],
				
			['created_by', 'exist', 'skipOnError' => true, 'targetClass' => User::class, 'targetAttribute' => ['created_by' => 'id']],
			['updated_by', 'exist', 'skipOnError' => true, 'targetClass' => User::class, 'targetAttribute' => ['updated_by' => 'id']],
		];
	}
	
	public function validateTemplateByType($attribute, $params = []): void
	{
		// Can't validate without type set
		if (!$this->type)
		{
			return;
		}
		
		// @see below for getAllowedTemplates();
		$allowedTemplates = $this->getAllowedTemplates();
		
		if ($this->$attribute !== null && !in_array($this->$attribute, $allowedTemplates, true))
		{
			$this->addError(
				$attribute,
				\Yii::t('app', 'The selected template "{template}" is not allowed for this category.', [
					'template' => $this->$attribute
				])
			);
			
			return;
		}
	}
	
	public function beforeValidate(): bool
	{
		if (!parent::beforeValidate())
		{
			return false;
		}
		
		// ...custom code here...
		
		/**
		* Set scenario automatically based on `type` and `template` to ensure validation 
		* rules apply correctly.
		*/
		if ($this->type && $this->template)
		{
			// Construct the combined scenario name by concatenating type and template with an underscore
			// For example: 'product_artwork', 'post_exhibition'
			$combinedScenario = $this->type . '_' . $this->template;
			
			// Check if scenario exists: use combined, else fallback to type or 'default'
			if (isset($this->scenarios()[$combinedScenario]))
			{
				// If the combined scenario exists, set it as the current scenario
				$this->setScenario($combinedScenario);
			}
			// If combined scenario does not exist, check if a scenario matching just the type exists
			elseif (isset($this->scenarios()[$this->type]))
			{
				// Set the scenario to the type-only scenario (e.g., 'product' or 'post')
				$this->setScenario($this->type);
			}
			// If neither combined nor type-only scenario exists,
			else
			{
				// Fallback to a default scenario to prevent validation errors
				$this->setScenario('default');
			}
		}
		// If only 'type' is set (no template)
		elseif ($this->type)
		{
			// Set the scenario to the type scenario
			$this->setScenario($this->type);
		}
		// If neither 'type' nor 'template' is set,
		else
		{
			// Set a generic default scenario so validation can still proceed without errors
			$this->setScenario('default');
		}
		
		return true;
	}
	
	public function getTypeKey(): ?string
	{
		// Flip the typeMap so we can get key by value
		static $reverseMap = null;
		
		if ($reverseMap === null)
		{
			$reverseMap = array_flip(self::$typeMap);
		}
		
		return $reverseMap[$this->type] ?? null;
	}
	
	public function getType(): ?string
	{
		// integer from DB
		$intType = $this->getAttribute('type');
		
		return self::$typeLabels[$intType] ?? null;
	}
	
	public function setType(string $value): void
	{
		if (isset(self::$typeMap[$value]))
		{
			$this->setAttribute('type', self::$typeMap[$value]);
		}
		else
		{
			$this->setAttribute('type', null);
		}
	}
	
	public function getAllowedTemplates(): array
	{
		// Check if the category relation is loaded and has allowed templates
		if ($this->category && $this->category->getAllowedTemplates())
		{
			return $this->category->getAllowedTemplates();
		}
		
		// fallback to global allowed templates by 'type'
		return self::$allowedTemplatesByType[$this->type] ?? [];
	}
	
	public static function getAllowedTemplatesByType(int|string $type): array
	{
		if (is_string($type))
		{
			$type = strtolower($type);// normalize
			
			if (isset(self::$typeMap[$type]))
			{
				$type = self::$typeMap[$type];
			}
			else
			{
				// Unknown string type, return empty or error as you prefer
				return [];
			}
		}
		
		return self::$allowedTemplatesByType[$type] ?? [];
	}
	
	public static function getAllAllowedTemplates(): array
	{
		return self::$allowedTemplatesByType;
	}
	
	public static function getTemplateList(): array
	{
		$templates = self::$templates;
		
		// Use keys and values the same or map them to friendly labels
		$labels = [
			'item' => \Yii::t('app', 'Item'),
			'artwork' => \Yii::t('app', 'Artwork'),
			'article' => \Yii::t('app', 'Article'),
			'exhibition' => \Yii::t('app', 'Exhibition'),
			'artist' => \Yii::t('app', 'Artist'),
			'catalog' => \Yii::t('app', 'Catalog'),
		];
		
		$list = [];
		
		foreach ($templates as $template)
		{
			$list[$template] = $labels[$template] ?? ucfirst($template);
		}
		
		return $list;
	}
}
```

view
```
<?php
declare(strict_types=1);

use app\models\Content;

/**
* Setup CategoryTypeMap + Template Engine
*
* Ensure $categoryTypeMap is an array, even if not provided
* This map links category IDs to their corresponding content types (e.g., 'post', 'product')
*/
$categoryTypeMap = $categoryTypeMap ?? [];
// Get the currently selected category ID from the model, or null if none selected
$currentCategoryId = $model->category_id ?? null;
// Initialize variable to hold the content type related to the selected category
$currentType = null;

// If there is a selected category and it exists in the categoryTypeMap,
// set the currentType to the mapped content type of that category
if ($currentCategoryId && isset($categoryTypeMap[$currentCategoryId]))
{
	$currentType = $categoryTypeMap[$currentCategoryId];
}
// Otherwise, if no category is selected or it is not in the map,
// fall back to using the content type directly from the model (if available)
else
{
	$currentType = $model->type ?? null;
}

// Based on the determined content type, fetch the allowed templates for that type
// If currentType is null or not found in allowedTemplatesByType, set templates to empty array
$templatesForCurrentType = $currentType && isset($allowedTemplatesByType[$currentType]) 
	? $allowedTemplatesByType[$currentType]
	: [];
?>

<?=  $form->field($model, 'category_id')->dropDownList($categoryOptions ?? [], [
	'id' => 'content-category',// Must be present for CategoryTypeMap + Template Engine
	'class' => 'form-control square',
	'prompt'  => \Yii::t('app', 'select a category...')
])->label('Category')->hint(\Yii::t('app', 'optional')); ?>


<?php
$allTemplates = Content::getTemplateList();
$allowedTemplatesListForType = array_intersect_key($allTemplates, array_flip($templatesForCurrentType));
?>
<?= $form->field($model, 'template')->dropDownList(
	$allowedTemplatesListForType,
	['id' => 'content-template', 'prompt' => \Yii::t('app', 'Select Template')]
); ?>
```

controller
```
class ContentController extends BaseController
{
	public function actionCreate(): Response|string
	{
		$model = new Content();
		if (!$model)
		{
			throw new YiiWebNotFoundHttpException(\Yii::t('app', 'Content not found'));
		}
		
		// Get category options early for category type map etc.
		$data = $this->getCategoryOptions(true);
		
		// For actionCreate only! Assign a default category_id if none is set (e.g. first in dropdown)
		if (!$model->category_id && !empty($data['categoryOptions']))
		{
			reset($data['categoryOptions']);
			$defaultCategoryId = key($data['categoryOptions']);
			$model->category_id = $defaultCategoryId;
		}
		
		$session = \Yii::$app->session;
		$request = \Yii::$app->request;
		
		if ($this->_debugMode)
		{
			LogHelper::debug('POST data (before load): ' . json_encode($request->post()), [
				'post data' => json_encode($request->post()),
				'method' => __METHOD__
			]);
		}
		
		if ($request->isPost)
		//if (($request->isPost) && ($model->load($request->post()) && $model->validate()))
		{
			if ($this->_debugMode)
			{
				// Should be empty on create
				LogHelper::debug('Model and POST data after loading:', [
					'model_attributes_json' => json_encode($model->attributes),
					'model_attributes_array' => $model->getAttributes(),
					'post_data' => $request->post(),
					'method' => __METHOD__,
				]);
			}
			
			// Load and validate using the assignScenarioThenLoad()
			$postData = $request->post('Content', []);
			if ($this->assignScenarioThenLoad($model, $postData, $data['categoryTypeMap'] ?? []))
			{
				if ($this->_debugMode)
				{
					LogHelper::debug("Content update scenario and key attributes after scenario set", [
						'type' => $model->type,
						'scenario' => $model->getScenario(),
						'combinedScenario' => $combinedScenario,
						'allScenarios' => implode(', ', array_keys($scenarios)),
						'attributes' => $model->getAttributes(),
						'keyAttributes' => [
							'type' => $model->type,
							'template' => $model->template,
							'category_id' => $model->category_id,
							'price' => $model->price,
							'purchase_options' => $model->purchase_options,
							'quantity' => $model->quantity,
							// Add more if needed
						],
						'method' => __METHOD__,
					]);
				}
				
				if ($model->validate())
				{
					if ($model->save())
					{
						if ($this->_debugMode)
						{
							LogHelper::debug('Saved content ID: ' . $model->id, [
								'model ID' => $model->id,
								//'price' => $model->price,// etc
								'method' => __METHOD__
							]);
						
							//$model->refresh();
						}
						
						$session->setFlash('success', \Yii::t('app', 'Created successfully.'));
						
						return $this->redirect(['view', 'id' => $model->id]);
					}
				}
				else
				{
					if ($this->_debugMode)
					{
						LogHelper::debug("Validation errors:\n" . print_r($model->errors, true), [
							'errors' => print_r($model->errors, true),
							'method' => __METHOD__
						]);
					}
				}
			}
		}
		else
		{
			// Pre-populate default data
			$model->loadDefaultValues();
		}
		
		// Gather categoryTemplatesMap and categoryTypeMap data
		$allowedTemplatesJson = Json::encode($data['categoryTemplatesMap'] ?? []);
		$categoryTypeMapJson = Json::encode($data['categoryTypeMap'] ?? []);
		
		// For actionCreate only! Set current template and type JS vars from model (category_id already set!)
		$currentTemplateJs = Json::encode($model->template ?? '');
		$currentTypeJs = Json::encode(
			$data['categoryTypeMap'][$model->category_id] ?? null
		);
		
		// Render JS with updated values
		$this->renderJS($allowedTemplatesJson, $categoryTypeMapJson, $currentTemplateJs, $currentTypeJs);
		
		return $this->render('create', [
			'model' => $model,
			'allowedTemplatesByType' => Content::getAllAllowedTemplates(),
			'categoryOptions' => $data['categoryOptions'],
			'categoryTypeMap' => $data['categoryTypeMap'],
			'contentSummaryLength' => $this->_contentSummaryLength,
			'mediaBlogImageRecSize' => $this->_mediaBlogImageRecSize,
			'mediaProductImageRecSize' => $this->_mediaProductImageRecSize,
		]);
	}

	private function assignScenarioThenLoad(Content $model, array $postData, array $categoryTypeMap): bool
	{
		// Extract category_id and template from posted data
		$categoryId = $postData['category_id'] ?? null;
		$template = $postData['template'] ?? null;
		
		// Determine the content type based on the category ID
		$type = $categoryTypeMap[$categoryId] ?? null;
		
		// Assign to model
		$model->type = $type;
		$model->template = $template;
		
		// Determine scenario based on type and template
		$typeKey = $model->type ?: 'default';// $model->type should already be string 'post' or 'product'
		$combinedScenario = $typeKey . '_' . $model->template;
		$scenarios = $model->scenarios();
		
		if (isset($scenarios[$combinedScenario]))
		{
			$model->setScenario($combinedScenario);
		} 
		elseif (isset($scenarios[$typeKey]))
		{
			$model->setScenario($typeKey);
		}
		else
		{
			$model->setScenario('default');
		}
		
		if ($this->_debugMode)
		{
			LogHelper::debug(
				'Scenario set: ' . $model->getScenario() . ', safe attributes: ' . implode(', ', $model->safeAttributes()), [
				'scenario set' => $model->getScenario(),
				'safe attribute' => implode(', ', $model->safeAttributes()),
			]);
		}
		
		// Load the model with POST data
		return $model->load($postData);
	}
	
	private function getCategoryOptions(bool $includeTypeMap = true): array
	{
		$categories = ContentCategory::find()->all();
		
		if (!$categories)
		{
			return [
				'categoryOptions' => [],
				'categoryTypeMap' => $includeTypeMap ? [] : null,
				'categoryTemplatesMap' => $includeTypeMap ? [] : null,
			];
		}
		
		// Build hierarchical and flat category list
		$hierarchicalCategories = ContentCategory::structureCategories($categories);
		$flatCategories = ContentCategory::flattenCategoriesDropdown($hierarchicalCategories);
		
		if (!is_array($flatCategories))
		{
			$flatCategories = [];
		}
		
		// Map integer type IDs to string keys expected in JS/toggle logic
		$typeLabels = [
			ContentCategory::TYPE_POST => 'post',
			ContentCategory::TYPE_PRODUCT => 'product',
			// Add other type mappings as needed
		];
		
		$categoryTypeMap = null;
		$categoryTemplatesMap = null;
		
		if ($includeTypeMap)
		{
			// Build categoryTypeMap and categoryTemplatesMap with type strings (not numeric IDs)
			$categoryTypeMap = [];
			$categoryTemplatesMap = [];
			
			foreach ($categories as $category)
			{
				$categoryTypeMap[$category->id] = $typeLabels[$category->type] ?? null;
			
				$allowedTemplates = $category->getAllowedTemplates();
				
				if (empty($allowedTemplates))
				{
					// fallback to global allowed templates by type
					$typeKey = $categoryTypeMap[$category->id] ?? '';
					$allowedTemplates = Content::getAllowedTemplatesByType($typeKey);
				}
				
				$categoryTemplatesMap[$category->id] = $allowedTemplates;
			}
		}
		
		return [
			'categoryOptions' => $flatCategories,
			'categoryTypeMap' => $categoryTypeMap,
			'categoryTemplatesMap' => $categoryTemplatesMap,
		];
	}
	
	private function renderJS(
		string $allowedTemplatesJson,
		string $categoryTypeMapJson,
		string $currentTemplateJs,
		string $currentTypeJs
	): void
	{
		$uniqueId = uniqid('', false);// Create 13-char unique string based on time
		$cacheKey = $this->_cacheKeyPrefix . $uniqueId . '_js_block_';
		$jsBlock = $this->getCachedJsBlock($cacheKey, function () use (
			$allowedTemplatesJson,
			$categoryTypeMapJson,
			$currentTemplateJs,
			$currentTypeJs
		)
		{
			/**
			* JavaScript
			* CSS Classes to control field visibility:
			* - Apply the class `.field-type-{type}` to all form fields shown for a specific content type,
			*   for example `.field-type-post` or `.field-type-product`.
			* - Apply the class `.field-template-{template}` to all form fields shown for a specific template,
			*   for example `.field-template-artwork` or `.field-template-exhibition`.
			* - Apply the class `.field-type-template-{type}-{template}` to form fields that should only be
			*   visible for the combined content type and template, for example `.field-type-template-product-artwork`.
			*
			* Examples:
			* Shows 'start_date' field only if content type is 'post':
			*
			* 	<?= $form->field($model, 'start_date', ['options' => ['class' => 'field-type-post']]); ?>
			*
			* Shows 'end_date' field only if template is 'exhibition' (regardless of type):
			* 
			* 	<?= $form->field($model, 'end_date', ['options' => ['class' => 'field-template-exhibition']]); ?>
			*
			* Shows 'artist' field only if content type is 'product' and template is 'artwork':
			* 
			*	<?= $form->field($model, 'artist', ['options' => [
			*		'class' => 'field-type-product field-template-artwork field-type-template-product-artwork'
			*	]]); ?>
			*/
			return <<<js
			(function(\$)
			{
				\$(function()
				{
					/* Map: category ID => array of allowed templates for that category 
						e.g. { "1": ["article", "exhibition"], "2": ["item", "artwork"] } */
					var categoryTemplatesMap = $allowedTemplatesJson;
					
					/* Map: category ID => content type string ('post', 'product', etc.) 
						e.g. { "1": "post", "2": "product" } */
					var categoryTypeMap = $categoryTypeMapJson;
					
					/* Initialize current template and type from PHP passed values, with fallback values */
					var currentTemplate = $currentTemplateJs || '';
					var currentType = $currentTypeJs || null;
					
					var \$category = \$('#content-category');
					var \$template = \$('#content-template');
					
					/* Given a category ID, return the content type as string ("post", "product", etc) */
					function getTypeForCategory(catId)
					{
						/* JSON keys are strings */
						catId = String(catId);
					
						return categoryTypeMap.hasOwnProperty(catId) ? categoryTypeMap[catId] : null;
					}
					
					/* Update template dropdown options based on category ID's allowed templates */
					function updateTemplateOptions(catId)
					{
						var templates = categoryTemplatesMap[catId] || [];
						\$template.empty();
						
						if (templates.length === 0)
						{
							/* No valid templates: disable dropdown and prompt user */
							\$template.append(\$('<option>').val('').text('Select a template'));
							\$template.prop('disabled', true);
						}
						else
						{
							/* Populate dropdown with templates, label capitalized for user friendliness */
							\$.each(templates, function(i, val)
							{
								var label = val.charAt(0).toUpperCase() + val.slice(1);
								\$template.append(\$('<option>').val(val).text(label));
							});
							
							\$template.prop('disabled', false);
						}
						
						/* Set the current template if it is present in the new options, else default to first option
							Array.prototype.includes is ES6+ */
						if (\$.inArray(currentTemplate, templates) !== -1)
						{
							\$template.val(currentTemplate);
						}
						else
						{
							\$template.val(templates[0] || '');
						}
					}
					
					/* Show/hide form fields based on the current type and template using class conventions */
					function toggleFields(type, template)
					{
						/*console.log('toggleFields called with:', type, template);*/
						
						/* Hide all fields that are tagged by any type or template CSS classes */
						\$('[class*="field-type-"]').hide();
						\$('[class*="field-template-"]').hide();
						\$('[class*="field-type-template-"]').hide();
						
						/* Show all fields matching current type e.g., '.field-type-post' */
						if (type)
						{
							\$('.field-type-' + type).show();
						}
						/* Show all fields matching current template e.g., '.field-template-artwork' */
						if (template)
						{
							\$('.field-template-' + template).show();
						}
						/* Show fields that require both specific type and template, e.g., '.field-type-template-product-artwork' */
						if (type && template)
						{
							\$('.field-type-template-' + type + '-' + template).show();
						}
					}
					
					/* Initialization on page load: */
					var initialCategoryId = \$category.val();
					var initialType = getTypeForCategory(initialCategoryId) || currentType;
					
					if (!categoryTemplatesMap || Object.keys(categoryTemplatesMap).length === 0 || !initialCategoryId)
					{
						/* No categories/templates data available OR no category selected:
							disable template dropdown & hide fields */
						\$template.empty()
							.append(\$('<option>').val('').text('Select a category first'))
							.prop('disabled', true);
						
						toggleFields(null, null);
					}
					else
					{
						/* Otherwise, fill templates for selected category and toggle fields accordingly */
						updateTemplateOptions(initialCategoryId);
						var initialTemplate = \$template.val();
						
						toggleFields(initialType, initialTemplate);
					}
					
					/* Event handler: when category selection changes, update type and templates accordingly */
					\$category.on('change', function()
					{
						var catId = \$(this).val();
						
						/*console.log('Category changed to:', catId);
						console.log('Allowed templates:', categoryTemplatesMap[catId]);
						console.log('Current template before update:', currentTemplate);*/
						
						var type = getTypeForCategory(catId);
						
						if (!catId || !type)
						{
							/* No valid category or type: disable templates, hide all fields */
							\$template.empty()
								.append($('<option>').val('').text('Select a category first'))
								.prop('disabled', true);
							
							toggleFields(null, null);
							
							return;
						}
						
						/* Update globals so changes are tracked for template changes as well */
						currentType = type;
						updateTemplateOptions(catId);
						currentTemplate = \$template.val();
						toggleFields(currentType, currentTemplate);
					});
					
					/* Event handler: when template selection changes, toggle fields based on new template */
					\$template.on('change', function()
					{
						var template = \$(this).val();
						var type = getTypeForCategory(\$category.val()) || currentType;
						
						toggleFields(type, template);
						
						/* track current template for persistence */
						currentTemplate = template;
					});
				});
			})(jQuery);
			js;
		});
		
		$this->view->registerJs($jsBlock, View::POS_END);
	}
}
```
The issue is:
- Need Category and Template in order to know what scenario is setup
- This needs to be auto set via pjax ajax? 
- Right now if I "create" content, default is set
- Once the form is saved, scenario seems set properly
- perhaps a auto save? and create a cronjob for any content created that wasn't complete is removed after xx time