Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-11-05 16:48:47

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Check if article exists, provide fallback content if not

For some of my theme modules, I’d like to check whether an article exists, and provide fallback content if not.

So, for example, check if an article in section pageless-content with category homepage-heading exists. If so, display that. If not, display some hard-coded text.

Is this possible? Thanks!

Offline

#2 2020-11-05 17:01:51

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Check if article exists, provide fallback content if not

Hi Phil,

this could work:

<txp:article_custom ...>
    display that
<txp:else />
    hard-coded text
</txp:article_custom>

Offline

#3 2020-11-05 17:03:47

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Check if article exists, provide fallback content if not

Actually, I might have found the answer in another thread?…

<txp:evaluate test="article_custom">
    <txp:article_custom form="-module--text--heading01" section="pageless-content" category="homepage-heading" />
<txp:else />
    <txt:output_form form="-module--text--heading01">
        <txp:yield name="title" default="Placeholder title" />
        <txp:yield name="excerpt" default="Placeholder excerpt" />
    </txp:output_form>
</txp:evaluate>

Plus some conditional code in my -module--text--heading01 form to check/get the fallback yields.

Offline

#4 2020-11-05 17:05:20

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Check if article exists, provide fallback content if not

etc wrote #326682:

this could work …

Oh, I didn’t know you could put a <txp:else /> within a <txp:article_custom> tag. Let me think about that. Cheers.

Offline

#5 2020-11-05 17:08:25

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Check if article exists, provide fallback content if not

philwareham wrote #326684:

Oh, I didn’t know you could put a <txp:else /> within a <txp:article_custom>.

I don’t remember whether/how it works with forms.

Offline

#6 2020-11-06 10:02:02

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Check if article exists, provide fallback content if not

Can I load yield contents into a <txp:article_custom> tag’s section, category and id attributes, when said article_custom tag is within an output_form? Can’t seem to get it to work.

Offline

#7 2020-11-06 21:27:01

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Check if article exists, provide fallback content if not

philwareham wrote #326686:

Can I load yield contents into a <txp:article_custom> tag’s section, category and id attributes, when said article_custom tag is within an output_form? Can’t seem to get it to work.

I can’t see why it would not work, need to see the forms code.

Offline

#8 2020-11-06 21:42:40

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Check if article exists, provide fallback content if not

Ignore my last post. I got it working now thanks.

Offline

Board footer

Powered by FluxBB