Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2013-05-31 08:04:44

whpjm
Member
Registered: 2009-04-24
Posts: 15

if statement

hello

i have this code
<table>
<tr>
<td><img src=”<txp:custom_field name=“custom1” />”></td>
<td>
<h2><txp:title /></h2>
<txp:permlink class=“terug”>bekijk de foto’s >></txp:permlink>
<p>Fotografie: <txp:custom_field name=“custom2” /></p>
</td>
</tr>
</table>

mine question is:
when title = “Omroep Zeeland”
then will i not show <txp:permlink class=“terug”>bekijk de foto’s >></txp:permlink>
<p>Fotografie: <txp:custom_field name=“custom2” /></p>

how do i make an if-statement ?

with greetings

wilbert

Offline

#2 2013-05-31 08:18:25

kees-b
Member
From: middelburg, nl
Registered: 2004-03-03
Posts: 235
Website

Re: if statement

whpjm wrote:


when title = “Omroep Zeeland”
how do i make an if-statement ?

If it’s only one article, and you know it’s id, you can exclude it by: <txp:if_article_id>

-kees

…met groet uit zeeland

Offline

#3 2013-05-31 08:25:10

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

Re: if statement

whpjm wrote:

how do i make an if-statement ?

Another way is to use txp:variable and txp:if_variable, a bit like this:

<txp:hide> Assign the title to a variable called my_title </txp:hide>
<txp:variable name="my_title"><txp:title /></txp:variable>
<table>
   <tr>
      <td><img src="<txp:custom_field name="custom1" />"></td>
      <td>
         <h2><txp:variable name="my_title" /></h2>
         <txp:if_variable name="my_title" value="Omroep Zeeland">
            <txp:hide> Do not display the permlink </txp:hide>
         <txp:else />
            <txp:permlink class="terug">bekijk de foto's >></txp:permlink>
            <p>Fotografie: <txp:custom_field name="custom2" /></p>
         </txp:if_variable>
      </td>
   </tr>
</table>

But kees-b’s version is neater if it’s only going to be one article and you don’t mind using article IDs.

EDIT: another approach might be to use txp:if_custom_field, assuming that you won’t want to display the content if custom2 is empty. That means the logic would work across articles instead of being constrained to one particular article.

Last edited by Bloke (2013-05-31 08:28:49)


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 2013-05-31 09:59:35

whpjm
Member
Registered: 2009-04-24
Posts: 15

Re: if statement

thanks!!

Offline

Board footer

Powered by FluxBB