1
votes

I'm trying to display social icons if user check checkbox in template varribles.
So i made everything I need to display this checkbox on each page (i have 1 template only) in template varribles.
Next i put this code into base.html (i use static files for all chunks and template - this file is BaseTemplate static file)

<?php if ($modx->getTemplateVar(1,'Yes')) { ?>
  <a href="#"><img src="assets/templates/default/images/facebook.png" alt="Facebook" style="width: 26px; height: 26px; border: 0; margin-left: 40px;" /></a>
  <a href="#"><img src="assets/templates/default/images/twitter.png" alt="Twitter" style="width: 26px; height: 26px; border: 0; margin-left: 10px;" /></a>
  <a href="#"><img src="assets/templates/default/images/linkedin.png" alt="LinkedIn" style="width: 25px; height: 25px; border: 0; margin-left: 10px;" /></a><br /><br />
<?php } ?>

Also i tried:

<?php if ($modx->getTemplateVar($social,'Yes')) { ?>

where social is a name of my TV, 1 is id of my TV.

And this is what i get on website:

getTemplateVar($social,'Yes')) { ?>

I though this is because i cant use php in chunks/template file, so i create snippet and put code to check TV is checked into it, but this didnt give me any results.

Here is documentation i read to use TV.
What em i doing wrong? How to use TV in this way, not as a filter while display resource?

2
What version of Modx are you using? - OptimusCrime
MODX Revolution 2.2.0-pl2 (advanced) - miszczu

2 Answers

4
votes

Try this, you don't need to use a snippet or write any code to make this work,

In your template [base.html]:

[[*social:eq=`Yes`:then=`[[$YourSocialHTMLChunk]]` ]] 

[better yet, change your "social" TV to a numeric type of 1 or 0, you may have to double check the output filters: http://rtfm.modx.com/display/revolution20/Input+and+Output+Filters+(Output+Modifiers), I'm not sure if the 'eq' will work on a string... ]

Then stick all your social links into whatever you want to name YourSocialHTMLChunk

0
votes

You can use pure PHP in templates or chunks in Modx. If you have to use PHP, you need to create a Snippet for that.

You can reach your templatevarible in a template or chunk by writing [*templatevarname*] and it will output the content. Note that this only outputs the content for the page your are displaying.

If you want to load templatevariables from other resources, you MUST create a snippet for that.

Take a look at this wiki-page: http://wiki.modxcms.com/index.php/Placeholders_used_by_MODx_Pages_and_Templates

For a snippet you would have to write something like

[!yourSnippetName? &sid=`[[*id*]]`!]

Content of snippet:

$tvPr = $modx->getTemplateVarOutput(array("templatevarname"),$sid,1);
echo $tvPr['templatevarname'];

http://wiki.modxcms.com/index.php/API:getTemplateVarOutput