Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: Description field and tag
jakob wrote #299350:
Is it possible to retrieve a particular description field, for example from the default section when not in that section?
Yes, unless I’m missing something. You may need to use the type attribute to force the context, otherwise it picks up whatever context it thinks is best. For example, if you were on an individual article Page and you wanted the Section description to be checked, you’re out of luck unless you tell Txp that’s what you want.
As far as I can tell, your snippet works, but here’s an extended example from a regular Page template (that’s not set as the default Section):
<txp:if_description type="section">
Got Description for <txp:section/>: <txp:meta_description type="section" format="raw" />
<txp:else />
<txp:section_list sections="default">
Using fallback: <txp:meta_description format="raw" />
</txp:section_list>
</txp:if_description>
[ using format="raw" just so we can see the output on the page without viewing source ]
So that will display the default Section’s description if the current Section does not have a description. If you omit the type attribute from the conditional, it’ll output the default Section’s description if:
- there’s no article description and you’re in an individual article context
- there’s no section description and you’re in an article list context
Am I missing some esoteric use case here to provide a sensible fallback?
btw, the if_description docs are wrong and don’t mention the type attribute. Plus there’s a cateogry typo. Note to self: fix sometime.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: Description field and tag
Bloke wrote #299363:
As far as I can tell, your snippet works…
<txp:section_list sections="default">
Using fallback: <txp:meta_description format="raw" />
</txp:section_list>
My bad … you’re absolutely right: it does work (also without the wrapper). I have no idea what I did wrong the first time but it does work as you describe.
TXP Builders – finely-crafted code, design and txp
Offline