Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-05-03 13:00:02

hilaryaq
Plugin Author
Registered: 2006-08-20
Posts: 263
Website

Tricky how to pass variable from form

Hi guys!

I don’t know if this is possible and I haven’t used variables a lot but maybe it’s a variable condition..

I create an article for a single page, and I use the dropdown to override the default form to use page_single, I want to output a h1 tag on any page that does not use the page_single form, because page single takes the article heading as it’s h1, and on list pages I want the section title to be the h1.

Is there anyway for the page to recognise that page_single is the form being used? So that I can just say if page_single is being used do nothing, else show this content.. instead of having to hard-code the article list sections? Or is there any other way to achieve this?

It’s a weird one I tried a few combos with variable tags but they don’t seem to work for me!

Thanks in advance for any ideas!

Last edited by hilaryaq (2020-05-03 13:01:26)


…………………
I <3 txp
…………………

Offline

#2 2020-05-03 13:46:06

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,328
Website

Re: Tricky how to pass variable from form

If you’re in an article context, $thisarticle contains an override_form item, which is conveniently available as a custom field. So…

<txp:if_individual_article>
    <txp:if_custom_field name="override_form" not value="page_single">
        <h1><txp:title /></h1>
    </txp:if_custom_field>
</txp:if_individual_article>

You can omit the if_individual_article wrapper if you already know you’re in that context.

Hope that helps.

Last edited by Bloke (2020-05-03 13:48:37)


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

#3 2020-05-03 13:48:13

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,346
Website

Re: Tricky how to pass variable from form

Hi,

Did you think of using JavaScript ?

Cheers.

Offline

#4 2020-05-03 14:24:24

hilaryaq
Plugin Author
Registered: 2006-08-20
Posts: 263
Website

Re: Tricky how to pass variable from form

Bloke wrote #322805:

If you’re in an article context, $thisarticle contains an override_form item, which is conveniently available as a custom field. So…

<txp:if_individual_article>...

You can omit the if_individual_article wrapper if you already know you’re in that context.

Hope that helps.

Thanks Stef! I was meaning in the page content so in my default page:

<txp:if_custom_field name=“override_form” not value=“page_single”>
<h1><txp:section title=“1” /></h1>
</txp:if_custom_field>

But that code doesn’t work it’s probably more for an article form?


…………………
I <3 txp
…………………

Offline

#5 2020-05-03 14:26:59

hilaryaq
Plugin Author
Registered: 2006-08-20
Posts: 263
Website

Re: Tricky how to pass variable from form

Dragondz wrote #322806:

Hi,

Did you think of using JavaScript ?

Cheers.

Hi! This was exactly what my husband said lol, I’m not that adept with it so I’d probably just hard-code it with the section name instead.. it would just be more elegant to be automated that if a client added a new page with multiple articles that it would automatically know the difference between a page with one article only (static to all intents and purposes), vs a page with multiple articles..

So I’d probably just stick in an if_section but I know it could be probably solved in the elegant way with js too!


…………………
I <3 txp
…………………

Offline

#6 2020-05-03 14:33:06

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,328
Website

Re: Tricky how to pass variable from form

hilaryaq wrote #322810:

I was meaning in the page content so in my default page

Depending on where you do this in your page, may determine your level of success.

You can use it in your page content but you need to make sure your article data is available first. Txp knows that you’re in an individual article or article list context right from the get-go, but as Txp parses your page content linearly, it doesn’t necessarily “know” what the article details are until it hits the <txp:article> tag.

So if you’re trying to do this ‘above’ that tag in your page flow, it won’t work.

In that case, wrap it in <txp:hide> and tell it to process the content on the second pass. This means, Txp sweeps your code, skips the bit in the ‘hide’ (for now), does the rest, loads up your article content when it hits the <txp:article> tag, then goes back for a second sweep and finds your ‘hidden’ content. It injects it at that point then displays the final page.

Untested, but try this:

<txp:hide process="2">
    <txp:if_custom_field name="override_form" not value="page_single">
        <h1><txp:title /></h1>
    </txp:if_custom_field>
</txp:hide>

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

#7 2020-05-03 14:41:42

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,328
Website

Re: Tricky how to pass variable from form

hilaryaq wrote #322811:

it would just be more elegant to be automated that if a client added a new page with multiple articles that it would automatically know the difference between a page with one article only (static to all intents and purposes), vs a page with multiple articles.

FWIW, I have done this with two page templates for some clients. I have one Page called “single” and one called “regular”. They both share 99% of the content – most of it provided by forms inserted by <txp:output_form> to maximise reuse. The main difference is the article tag has limit=“1” and there’s no ‘list’ view (and no heading link, as you’re doing here. You can detect which page is in use by testing the type="page" attribute from txp:page_url).

That means that if a client wants a section that is essentially ‘static’ (e.g. a contact page or a links page) they create a new section, assign the ‘single’ page template and add their article as normal to this section. Job done. No override forms.

Last edited by Bloke (2020-05-03 14:46:55)


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

#8 2020-05-03 14:46:57

hilaryaq
Plugin Author
Registered: 2006-08-20
Posts: 263
Website

Re: Tricky how to pass variable from form

Bloke wrote #322812:

Depending on where you do this in your page, may determine your level of success.

You can use it in your page content but you need to make sure your article data is available first. Txp knows that you’re in an individual article or article list context right from the get-go, but as Txp parses your page content linearly, it doesn’t necessarily “know” what the article details are until it hits the <txp:article> tag.

So if you’re trying to do this ‘above’ that tag in your page flow, it won’t work.

In that case, wrap it in <txp:hide> and tell it to process the content on the second pass. This means, Txp sweeps your code, skips the bit in the ‘hide’ (for now), does the rest, loads up your article content when it hits the <txp:article> tag, then goes back for a second sweep and finds your ‘hidden’ content. It injects it at that point then displays the final page.

Try this:

<txp:hide process="2">...

I tried hide before and after the article tag, and also tried without the hide after the article tag which didn’t work either..

Might not work, even if there was another solution that says if only one article exists in this section then do something would also work, as all static pages have only one article. The logic that every section page is an article list is what’s effecting it, if I could somehow mark ‘static’ page articles as individual article not article list pages it would be an easy solve too!

Thanks for all the help :)


…………………
I <3 txp
…………………

Offline

#9 2020-05-03 14:49:40

hilaryaq
Plugin Author
Registered: 2006-08-20
Posts: 263
Website

Re: Tricky how to pass variable from form

Bloke wrote #322813:

FWIW, I have done this with two page templates for some clients. I have one Page called “single” and one called “regular”. They both share 99% of the content – most of it provided by forms inserted by <txp:output_form> to maximise reuse. The main difference is the article tag has limit=“1” and there’s no ‘list’ view (and no heading link, as you’re doing here. You can detect which page is in use by testing the type="page" attribute from txp:page_url).

That means that if a client wants a section that is essentially ‘static’ (e.g. a contact page or a links page) they create a new section, assign the ‘single’ page template and add their article as normal to this section. Job done. No override forms.

It’s a good workflow! I’ve been lazy with my one page should do everything approach lol. That would solve it too and probably be easier to read and edit the code too!


…………………
I <3 txp
…………………

Offline

#10 2020-05-03 14:52:15

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,328
Website

Re: Tricky how to pass variable from form

Ah, drat. I hoped it’d work. Well you can probably cheat:

Step 1. In your article form:

<txp:if_custom_field name="override_form" not value="page_single">
    <txp:variable name="multi_page" value="1" />
</txp:if_custom_field>

Step 2. In your page template:

<txp:hide process="2">
    <txp:if_variable name="multi_page" value="1">
        <h1><txp:title /></h1>
    </txp:if_variable>
</txp:hide>

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

Board footer

Powered by FluxBB