Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#145 2018-06-04 13:08:56

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,481
Website GitHub

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

Yes, if you’re using 4.7.0 and can use a native shortcode, now would be a good time to migrate it. You can do everything in a shortcode you can do in a smd_macro. I will probably deprecate this plugin at some point.


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

#146 2018-06-04 14:44:43

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,686
Website GitHub Twitter

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

Bloke & Destry wrote

use native shortcode

Hmmm. I see the examples are making heavy use of the yield tag. Although I read many explanations about it in this forum, i did not really understand it yet. I will experiment though as I always prefer using native tags.


Yiannis
——————————
neme.org | hblack.net | State Machines | NeMe @ github
I do my best editing after I click on the submit button.

Offline

#147 2018-06-05 16:53:35

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,686
Website GitHub Twitter

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

Just thought I’ll stop in to say that I have replaced all the smd_macros with native shortcode and it works wonderfully!!! It took less than half a day to write the shortcodes and search and replace all instances I had in the articles. This feature is an amazing leap forward for txp which deserved a jump to version 5.0!!! Way to go guys!!!!


Yiannis
——————————
neme.org | hblack.net | State Machines | NeMe @ github
I do my best editing after I click on the submit button.

Offline

#148 2018-06-05 22:56:12

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 2,435
Website

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

Yes, native shortcode is amazingly magic. Once you ”get” <txp:yield / the sky is the limit.


Where is that emoji for a solar powered submarine when you need it ?

Offline

#149 2018-06-06 08:39:47

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,481
Website GitHub

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

colak wrote #312354:

This feature is an amazing leap forward for txp

Another satisfied customer :) I love it too.

Thank Oleg, it was his idea. And Jukka for making rah_beacon in the first place, on which this feature is based.


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

#150 2018-06-06 09:01:00

etc
Developer
Registered: 2010-11-11
Posts: 4,436
Website GitHub

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

Bloke wrote #312369:

Thank Oleg, it was his idea.

Nope, ‘twas Phil, I’ve just coded.

Offline

#151 2019-12-21 10:32:39

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

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

Inside my macro I have some php. I test it with a simple

<txp:php>
echo ‘hello world’;
</txp:php>

to make sure it is not the php itself.

When I use the macro inside of my <txp:body/> all works fine.
When I try to use it just inside of <txp:article/> it works also but not the php-part.
In my peferences of the textpattern installation I have “allow php” in articels and pages checked.

Any idea why this is happening?

Last edited by demoncleaner (2019-12-21 10:32:50)

Offline

#152 2019-12-21 10:42:18

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,481
Website GitHub

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

demoncleaner wrote #320636:

When I use the macro inside of my <txp:body/> all works fine. When I try to use it just inside of <txp:article/> it works also but not the php-part.

That’s to do with Txp 4.7’s parser disallowing PHP from running on anything secondpass or higher (for security). See this discussion for more info and workarounds. If you can wait a day or two, the 4.8 beta will hopefully be out, where this restriction has been lifted.

And, btw you shouldn’t need this plugin any more. I’m retiring it. Textpattern can do everything it could, far cleaner and faster and safer using special shortcode forms. Check ‘em out and if you need any help migrating to the core solution, just holler on the forum.


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

#153 2019-12-21 11:01:59

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

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

Thanks Stef,

actually I am still using smd_macro a lot. Did not realize that it can be done better and cleaner without it. I will dig into shortcode forms.

Apart from that I can wait for 4.8.

Thanks again for your fast reply and Merry Christmas!

Last edited by demoncleaner (2019-12-21 11:02:39)

Offline

#154 2020-02-06 17:09:59

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,481
Website GitHub

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

Way back in the mists of time, I posted a little macro that used a hunk of PHP to output a series of images scattered within your article.

The premise is that, after attaching a bunch of images to your article image field via whatever means (typing, plugin, …) it’d be handy to drop them into your article – inline – in the order given in the article image field. So you could swap the order around – even change the image IDs in the list – and the article would render them in the given order, without you needing to change anything else.

I’m just here to report that it’s now a cinch to do natively in core with no PHP in 4.8+. Here’s how:

  1. Establish a Txp Form (of any type) named ‘nextimg’.
  2. Put the code below in it.
  3. Stick your article image IDs as a comma-separated list in your article image field. Even use the new ranges feature if you like.
  4. Anywhere you like – body text, excerpt, other pages, forms, wherever there’s article context – put in <txp::nextimg /> and the next image in the list will be displayed right there.

It uses a variable to keep track of which image you’re up to, per article, so it can be used safely in lists if you want to display thumbnails alongside your teaser.

Here’s the shortcode:

<txp:if_article_image>
   <txp:if_variable not name='imgoff_<txp:article_id />'><txp:variable name='imgoff_<txp:article_id />' value="0" /></txp:if_variable>
    <txp:images offset='<txp:variable name=''imgoff_<txp:article_id />'' />' limit="1" form='<txp:yield name="render" default="images" />' />
    <txp:variable name='imgoff_<txp:article_id />' add />
</txp:if_article_image>

There might be an even more efficient way to do this but I’m covering my bases in the initial variable setup to ensure they are initialized to 0. That might not be strictly necessary.

I’m bouncing the actual img tag rendering out to another form called images here. That could be whatever you want.

You can pass into the shortcode the ‘class’ attribute to set that (see <txp:yield /> below) and I’ve also set it to permit you to override the form too via the render attribute.

Anyway, my images Form uses smd_thumbnail to set up a simple srcset but you don’t have to go that far. Just an example:

<txp:variable name="caption" value='<txp:image_info />' />
<txp:if_variable name="caption">
    <figure itemprop="image" itemscope itemtype="https://schema.org/ImageObject" class="<txp:yield name='class' />">
        <img itemprop="url contentUrl" src="<txp:image_url link='0' />" srcset="<txp:smd_thumbnail type="Mobile" display="url" /> 480w, <txp:image_url /> 1280w" alt="<txp:image_info type='alt' />" class="article-image">
        <figcaption itemprop="caption">
            <txp:variable name="caption" />
        </figcaption>
    </figure>
<txp:else />
    <p itemprop="image" itemscope itemtype="https://schema.org/ImageObject" class="<txp:yield name='class' />">
        <img itemprop="url contentUrl" src="<txp:image_url link='0' />" alt="<txp:image_info type='alt' />">
    </p>
</txp:if_variable>

Enjoy!

Last edited by Bloke (2020-02-06 18:38:43)


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

#155 2020-02-06 17:18:17

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,686
Website GitHub Twitter

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

That would be an excellent tip for txp.tips!


Yiannis
——————————
neme.org | hblack.net | State Machines | NeMe @ github
I do my best editing after I click on the submit button.

Offline

#156 2020-02-06 17:19:27

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,481
Website GitHub

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

Yeah, good idea. When it’s ironed out and made as efficient as possible, I’ll pass it on to Julian for inclusion.


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