Jump to content
  • 0

Custom Varuiables


Juan GG Host

Question

I'm currently including additional info on my product group pages with if statements:
 

{if $gid eq '11'}


I'm wondering if there is a way to define custom variables, which I can more easily manage, and thus simplify my template files. For example, there is the built in $productGroup.features variable (is variable the right term?).
 

<ul class="list-features">
  {foreach $productGroup.features as $features}
  <li>{$features.feature}</li>
  {/foreach}
</ul>

So in the same way, could I define my own? For example:

$productGroup.promoVideo
$productGroup.additionalFeatures
$productGroup.addons
$productGroup.additionalBanner


 

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Yes, it is possible to define custom variables in your WHMCS templates to simplify your template files and make them easier to manage. There are a few different ways you can do this, depending on where you want to use the variables and what type of data you want to store in them.

One way to define custom variables is to use the assign function in your template files. For example, you can define a custom variable called promoVideo like this:

{assign var='promoVideo' value='https://www.youtube.com/watch?v=dQw4w9WgXcQ'}


You can then use this variable in your template like this:

<div class="promo-video">
    <iframe src="{$promoVideo}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>


Another way to define custom variables is to use the set_template_var function in a custom hook or module function. For example, you can define a custom variable called additionalFeatures like this:

function mymodule_additional_features($vars) {
    $additionalFeatures = array('Feature 1', 'Feature 2', 'Feature 3');
    set_template_var('additionalFeatures', $additionalFeatures);
}
add_hook('ClientAreaPage', 1, 'mymodule_additional_features');


You can then use this variable in your template like this:

<ul class="list-additional-features">
    {foreach $additionalFeatures as $feature}
    <li>{$feature}</li>
    {/foreach}
</ul>

 

Edited by PUQ
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated