Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
How to use a variable ...!?
On this page (under construction) > www.meeuwenveen.nl … in the sidebar I’m publishing special .linkbox(es). With this peace of code (form):
<a href="<txp:link_url />" target="_blank"><div class="linkbox">
<h3><txp:link_name escape="html"/></h3>
<p><txp:link_description escape="" /></p>
</div></a>
But not every artist has a site or page on the internet. E.g. Jeroen Vernooij doesn’t have one. What to code to make the box link to a page if there is an url … and when there’s not. I’m guessing it’s time for a variable, but I’m not good at this. Okay, I’ll give it a try:
<txp:variable name="href" value="<txp:link_url />" />
<txp:if_variable name="href" value="<txp:link_url />">
<a href="<txp:link_url />" target="_blank"><div class="linkbox">
<h3><txp:link_name escape="html"/></h3>
<p><txp:link_description escape="" /></p>
</div></a>
<txp:else />
<div class="linkbox">
<h3><txp:link_name escape="html"/></h3>
<p><txp:link_description escape="" /></p>
</div>
</txp:if_variable>
… mmm, it’s not working. Can somebody give me a hand?
Last edited by RedFox (2016-03-01 09:05:02)
Offline
Re: How to use a variable ...!?
Hi,
You could try
<txp:variable name="href" value='<txp:link_url />' />
<txp:if_variable name="href" value="">
<div class="linkbox">
<h3><txp:link_name escape="html"/></h3>
<p><txp:link_description escape="" /></p>
</div>
<txp:else />
<div class="linkbox">
<h3><a href="<txp:link_url />" target="_blank"><txp:link_name escape="html"/></a></h3>
<p><txp:link_description escape="" /></p>
</div>
</txp:if_variable>
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: How to use a variable ...!?
Or use txp:variable as a container to avoid single- and double-quote shenanigans if/when things get complicated:
<txp:variable name="href"><txp:link_url /></txp:variable>
Just bear in mind that newlines are important when doing it that way. So the above is actually different from:
<txp:variable name="href">
<txp:link_url />
</txp:variable>
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: How to use a variable ...!?
Ah … if the value is empty than … but I was close … thanks both … :)
Offline
Pages: 1