Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#157 2020-06-10 11:59:21

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 220
Website

Re: smd_macro: Create custom virtual Txp tags that do stuff

I was using smd_macro before like this:

<txp:macroname>
{smd_container}
</txp:macroname>

Now this can be done nicely with an ouputform <txp::macroname>
But how could I achieve the “containering”
Am I missing something? What would be the substitution of {smd_macro} in a form setup inside and article?

Last edited by demoncleaner (2020-06-10 11:59:35)

Offline

#158 2020-06-10 12:05:40

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

Re: smd_macro: Create custom virtual Txp tags that do stuff

demoncleaner wrote #323685:

how could I achieve the “containering”

Wrap your content with <txp::form_name>your container</txp::form_name> and then access the contained content via the yield tag without attributes (just note there’s a bug in 4.8.1, so please use 4.8.2-dev if you’re doing this, as that’s been patched and will be out very soon).

You can also pass parameters in via attributes:

<txp::form_name size="big" colour="yellow" />

And then access those inside your form, with the yield tag and <txp:if_yield> if you like:

<ul>
<li>Chosen size: <txp:yield name="size" default="medium" /></li>
<li>Chosen colour: <txp:yield name="colour" default="red" /></li>
<txp:if_yield name="width">
   <li>Chosen width: <txp:yield name="width" /></li>
</txp:if_yield>
</ul>

Hope that helps.


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

Online

#159 2020-06-10 12:16:07

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 220
Website

Re: smd_macro: Create custom virtual Txp tags that do stuff

Damn! I knew it was too simple… So far I was using yield always with a name attribute and I thought it needed it. The rest I knew already but thanks for pointing it out again.

So <txp:yield/> (without a parameter) = {smd_container}

I just installed 4.8.2 dev version and it works perfect. Thanks Stef.

Last edited by demoncleaner (2020-06-10 12:16:44)

Offline

#160 2020-06-10 12:23:58

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

Re: smd_macro: Create custom virtual Txp tags that do stuff

demoncleaner wrote #323687:

So <txp:yield/> (without a parameter) = {smd_container}

Yes, and <txp:yield else /> gives you access to any ‘false’ (else) branch in your form.


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

Online

#161 2020-06-10 22:57:56

singaz
Member
Registered: 2017-03-12
Posts: 150

Re: smd_macro: Create custom virtual Txp tags that do stuff

Bloke wrote #321551:

Just an example:

Great code, thanks!

I am adding decoding = "async" so that PageSpeed Insights does not swear.

<img decoding="async" src="...........


Sorry my horror English. I’m learning textpattern, I’m learning English

Offline

Board footer

Powered by FluxBB