Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2015-06-16 07:29:39

RedFox
Member
From: Netherlands
Registered: 2005-03-25
Posts: 805
Website

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

#2 2015-06-16 08:24:03

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,007
Website GitHub Mastodon Twitter

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

#3 2015-06-16 08:51:18

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

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

#4 2015-06-16 09:41:45

RedFox
Member
From: Netherlands
Registered: 2005-03-25
Posts: 805
Website

Re: How to use a variable ...!?

Ah … if the value is empty than … but I was close … thanks both … :)

Offline

Board footer

Powered by FluxBB