Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>While I don't recommend the syntax, you can put raw HTML code inline inside a php function.</p> <pre><code>&lt;?php function code_block( $jdoc_name ) { global $TopColClass; //// for variables created outside the function to be visible inside it, we have to include them with "global" ?&gt; &lt;div id="top-col" class="&lt;?php echo $TopColClass; ?&gt; columns"&gt; &lt;div class="panel"&gt; &lt;jdoc:include type="modules" name="&lt;?php echo $jdoc_name; ?&gt;" style="html5" /&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php } $MODULES = array( 'top-col-1', 'top-col-2', 'top-col-3', ); //// .... //// in the page body a foreach loop would also be a good idea: foreach( (array)$MODULES as $module_name ) { if ($this-&gt;countModules( $module_name )) { code_block( $module_name ); } } ?&gt; </code></pre> <hr> <p>EDIT, to solve as requested:</p> <pre><code>&lt;?php function code_block( $jdoc_name ) { global $TopColClass; //// for variables created outside the function to be visible inside it, we have to include them with "global" ?&gt; &lt;div id="top-col" class="&lt;?php echo $TopColClass; ?&gt; columns"&gt; &lt;div class="panel"&gt; &lt;jdoc:include type="modules" name="&lt;?php echo $jdoc_name; ?&gt;" style="html5" /&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php } function module( $prefix, $comma_seperated_suffixes ) { foreach( (array)explode( ",", $comma_seperated_suffixes ) as $suffix ) { $module_name = $prefix.trim($suffix); code_block( $module_name ); } } //// shorter call, as requested :) module("top-col-", "1,2,3"); ?&gt; </code></pre> <hr> <p>Final Edit, transformed into a class</p> <pre><code>&lt;?php class tovolt{ function tovolt() { //// constructor function - used to setup default variable states, etc. - if this is omitted PHP may have a fit ( depending on version and config ) } public static $TopColClass = 'default-value'; function code_block( $jdoc_name ) { ?&gt; &lt;div id="top-col" class="&lt;?php echo self::$TopColClass; ?&gt; columns"&gt; &lt;div class="panel"&gt; &lt;jdoc:include type="modules" name="&lt;?php echo $jdoc_name; ?&gt;" style="html5" /&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php } function module( $prefix, $comma_seperated_suffixes ) { foreach( (array)explode( ",", $comma_seperated_suffixes ) as $suffix ) { $module_name = $prefix.trim($suffix); self::code_block( $module_name ); } } } //// calling the class tovolt::$TopColClass = 'new-value'; //// if you need to change: $TopColClass tovolt::module("top-col-", "1,2,3"); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload