You are not logged in.
Not a hard one really, but I think, really useful
If the custom field is empty. ie: if it wasn’t filled in at the writing of the article, then it won’t be present in the display. I use this for displaying information about artworks at artiswork.org for instance.
<p> <txp:if_custom_field name="materials"> <strong>materials: </strong> <txp:custom_field name="materials" /><br/> </txp:if_custom_field>
<txp:if_custom_field name="size if applicable"> <strong>size: </strong> <txp:custom_field name="size if applicable" /><br/> </txp:if_custom_field>
<txp:if_custom_field name="year/date"> <strong>date: </strong> <txp:custom_field name="year/date" /><br/> </txp:if_custom_field> </p>
If this is a little more geared toward the textbook (basic use) sorry :)
Last edited by ma_smith (2006-01-07 22:33:35)
<txp:custom_field name="year/date" /><br/>
I dont know if the mistake above was intentional or it was part of the technique suggested by ma_smith.
In the above chunk, the value of “name” attribute isnt the same for txp:if_custom_field and for txp:custom_field.
For the first (if_custom_field), the value is “materials” and for the second one (custom_field) the value is “year/date”.
This can be seen as a mistake or if you are smart enough, as a powerful technique: using the custom_fields to trigger code.
In this case, if there is any value (= it’s not empty) in “materials” custom field, it will return the value inside the “year/date” custom field.
Of course, it seems a bit difficult to find situations where this can be useful. Or maybe not.
I have no doubt that someone in this community will find a great example and then will come back here and post it in this thread.
La música ideas portará y siempre continuará
Oops. Thanks Maniqui. Good Catch. I would have been wondering about that on my site as well :) Guess that’s why they call you a moderator.
Oops AGAIN! I should have read your post better. I should have claimed that yes, indeed I am a genius coder and you all should hang on my every example, ha ha ah ha ah ha. (evil laugh). Oh well. :)
Last edited by ma_smith (2005-11-01 03:42:50)
A tip of how this technique could be useful for multilingual sites.
Let’s assume you want to have two sets of pages which would be crosslinked with links like “see this page in [another language]”. Set custom fields for the languages you want to support, name them, for example eng and ukr (for English and Ukrainian).
Write articles for those languages and assign them links of their sibling articles on the other language, say, you have an article in English with permanent link “/about/my-dog” and you have the same article in Ukrainian with permanent link “/about/my-dog-ukr”, then set “/about/my-dog” to the custom field “eng” in the article on Ukrainian and “/about/my-dog-ukr” to the custom field “ukr” in the article on English.
Then in the article form you use write a code similar to the following:
<txp:if_custom_field name="eng"> <a href="<txp:custom_field name="eng" />">this page in english</a> </txp:if_custom_field>
<txp:if_custom_field name="ukr"> <a href="<txp:custom_field name="ukr" />">this page in ukrainian</a> </txp:if_custom_field> <br />
That’s it! When it’s English link to Ukrainian article will be shown up and vice versa.
It’s just a basic example to give you an idea, hope it helps.
Plugin Composer — admin plugin to write your own plugins
Yura, not only is that an innovating use of conditionals, but it’s probably the most elegant solution to the multilingual site problem yet. Being that I don’t expect to translate every article I write, this is likely going to be perfect for my needs. As soon as I find the time, I’ll try it.
I use this tag alot on the company that I work for, on there webiste. Right now that site is in beta and the site should launch in Jan. and it well be 100% controled by TXP.
I use this tag to auto-generate the Add to Cart buttons used in the shopping cart system on the site. I use all 10 fields for the buttons and use the if tags to only display the buttons for the filled in feilds. Its awsome.
Any idea of how to output information if a custom field is not set to a certian value i.e., something like
<txp:if_custom_field name="colour" value!="red">blue</txp:if_custom_field>?
Last edited by Jeff_K (2005-12-09 20:01:49)
Have you tested using txp:else?
<txp:if_custom_field name="colour" value="red"> ...red... <txp:else /> ...blue... </txp:if_custom_field>
La música ideas portará y siempre continuará
custom_fields are the most powerful features in textpattern.
This howto was published in 2005, and still usefull till now days. Thank you squaredeye