PHPFront logo
PHPFront Online Documentation now available! PHPFront is available on Composer: composer require ox-harris/phpfront Contact us to place an ad here...

Setting Runtime Parameters

Affect the runtime behavior of PHPFront on specific elements with quite a few settings!

While PHPFront's API properties allow you to set general rendering settings, you can target specific elements to use different settings. The @param property in a compound argument supplies these settings in key => value pairs.

PHPFront strips each instruction and applies it on the current element.
The settings work per element, and sometimes, including its children.

Here are the valid working parameters, and we'll compare them to the regular API global properties where available.

Runtime Parameters

Content-Type

Specifies the type of content provided so as to properly create the right node.

Global Setting: none
Usage:

      
      	
		// Data contains a HTML entity that needs to be encoded
		$data = 'Here comes John & Doe';
        
		// 1. Create this content as text node for the element
		$PHPFront->assign($element_selector, array(
			'@content' => $data,
			'@params' => array('content_type' => 'TEXT'))
        );
		// $data is going to be saved in the element as: Here comes John & Doe
		// Notice the entity encoding

		// 2. Create this content as Character Data Section (CDATA) for the element
		$PHPFront->assign($element_selector, array(
			'@content' => $data,
			'@params' => array('content_type' => 'CDATA'))
		);
		// $data is going to be saved in the element as-is
		// without any entity encoding
                
      
      

Where not specified, PHPFront will create content as Character Data Section if it contains no HTML tags, but as standard Element Node if it contains HTML tags.

On-Content-Empty

Tells what to do when the supplied content to an element is empty. This becomes very useful if you find it difficult to test the content out yourself.

Global Setting: none
Usage:

      
      	
		// Do not render this element
        $PHPFront->assign($element_selector, array(
        	'@content' => $data,
            '@params' => array('on_content_empty' => 'no_render')
        ));
        
        // Render this element, but clear whatever existing content it may have
        $PHPFront->assign($element_selector, array(
        	'@content' => $data,
            '@params' => array('on_content_empty' => 'clear')
        ));
        
        // Render this element, but set an attribute on the element so that if need be, 
        // we can find all elements whose content was empty via CSS or JS
        $PHPFront->assign($element_selector, array(
        	'@content' => $data,
            '@params' => array('on_content_empty' => 'set_flag')
        ));
        // With set flag, the attribute 'data-phpfront-content_empty = "true"' will be set on the element.
        
        // Both clear and set flag
        $PHPFront->assign($element_selector, array(
        	'@content' => $data,
            '@params' => array('on_content_empty' => 'clear_and_set_flag')
        ));
                
      
      

By default, PHPFront simply continues without modifying the element on-content-empty.

Value-Modifier

Specifies an external function for value modification. PHPFront will send the value (content), along with the matched element, for external modifications before rendering.
This way, you can extend the PHPFront functionality to perform virtually any task.

Global Setting: none
Usage:

      
      	
		// Send both content and element to a function named changeElementTagType()
        $PHPFront->assign($element_selector, array(
            '@content' => array('This is content 1', 'This is content 2', 'This is content 3'),
            '@params' => array('value_modifier' => 'changeElementTagType')
        ));
        
        // Send both content and element to a method named changeElementTagType() inside the class named ElementFactory
        $PHPFront->assign($element_selector, array(
            '@content' => array('This is content 1', 'This is content 2', 'This is content 3'),
            '@params' => array('value_modifier' => array('FunctionFactory', 'changeElementTagType'))
        ));
                       
      
      

Repeat-Fn

Specifies a particular algorithm to follow when elements have to be repeated in order to render any extra items in content array.

Global Setting: PHPFront::setRepeatFunctions()
Usage:

      
      	
      // Assign a specific repeat function. 
      // Overrides what has been set globally
      $PHPFront->assign($element_selector, array(
      	  '@content' => $data,
          '@params' => array('repeat_fn' => $repeat_fn, 'repeat_fn_y' => $repeat_fn_y)
      ));
                      
      
      

See the chapter Repeats for usage and valid values.

Summary

  • The @param property in a compound argument is used to supply rendering settings in key => value pairs to individual elements. Recall

We're good to go!

Back to Working with PHPFront

See Also