Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#25 2011-03-21 18:44:31

maruchan
Member
From: Ukiah, California
Registered: 2010-06-12
Posts: 595
Website

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

It would be great if the macros could appear as a drop-down menu in the Write tab, that would insert the code at the current cursor position.

This would be wonderful. Now that macros are here I’m thinking of ways to get around my clients typing in any txp tags. :-)

…so spoiled.

Last edited by maruchan (2011-03-21 18:44:43)

Offline

#26 2011-03-21 21:28:46

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

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

maruchan wrote:

Now that macros are here I’m thinking of ways to get around my clients typing in any txp tags. :-)

:-) I hadn’t really thought it a good use of code to duplicate what the tag builder does. That’s what you’re asking for, right? A way for someone to click a button and have it ask for all the attributes and then stuff the full macro tag at the cursor position?

With the best will in the world, the closest I could do is to perhaps use reflection to query the tag and put up a bunch of textboxes to allow people to type the values in. But what if one of your attributes was category or author or priv_level? How would I know to go and build a dropdown list of categories, authors or user groups? I suppose some inference could be made based on the name but what if you’d called your attributes rod, jane and freddy instead?

So as utopian as this sounds, I don’t think it’s within my expertise as a programmer. Unless someone can realign my thinking with some insight into how I might achieve such a beast in practice?

As I’ve alluded to already, I have a side project to help build macros for use with the image side of things. Anyone interested can always get in touch.


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

#27 2011-03-27 22:06:04

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

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

v0.11 fixes a tiny oversight if you are nesting macros. Essentially you were previously limited to two ‘levels’ but now that restriction is gone.

After upgrade you should probably resave each of your macros so the changes are propagated to them all, although if you’re not using macros-in-macros-in-tags-in-macros-in-attributes-in-tags or something equally mad, it’s probably not necessary right away as the v0.10 way of doing things is sufficient.

Thanks to maverick for stress-testing this and finding the limitation.


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

#28 2011-03-27 23:16:24

maverick
Member
From: Southeastern Michigan, USA
Registered: 2005-01-14
Posts: 976
Website

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

Bloke

Thanks for bending smd_macro to my crazy macro design. :)

It’s working great!

Mike

Offline

#29 2011-03-28 10:28:35

stickid
Member
From: Bremen, Germany
Registered: 2009-02-14
Posts: 15
Website

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

Hi,

first of all a big “THANX” for this brilliant Plugin!

I am asking myself if there is a way to access the attribute-values directly in PHP-code … using {atr_name} seems not to work here …

Hrrgh … my fault … It works (I just forgot to put some ‘ “ ‘ around the {atr_name})

Last edited by stickid (2011-03-28 10:41:48)

Offline

#30 2011-03-28 10:43:44

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

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

stickid wrote:

first of all a big “THANX” for this brilliant Plugin!

You’re welcome.

Hrrgh … my fault … It works (I just forgot to put some ‘ “ ‘ around the {atr_name})

Phew! I was going to say, I’m sure I tested it. Glad you got it going.


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

#31 2011-04-07 10:06:30

jelle
Member
Registered: 2006-06-07
Posts: 165

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

Hi Stef.

You are a genius! Another brilliant plugin to speed up my development time!

A simple (?) feature request to make you even more genius and this plugin more brilliant:

the same container functionality for smd_macro as output_form has.

I’m trying something like:

<txp:my_macro> Funky stuff!
</txp:my_macro>

my_macro would do it’s thing and also <txp:yield/> the Funky Stuff!

:)

Offline

#32 2011-04-07 11:59:52

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

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

jelle wrote:

Another brilliant plugin to speed up my development time!

Thank you. Enjoyed putting this one together.

the same container functionality for smd_macro as output_form has.

I did consider it, but couldn’t figure out how to build the macro with its contained content (it’s not like a built-in tag that understands the container already — I’m actually “building” the tag on the fly so it might need some nasty look-ahead to figure out if there was any contained content. Not sure as I didn’t really try it). I’ve not given it much more thought than that, so it might be possible to consider.

But one question: if you’d like to use it like that, why not just use <txp:output_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

Offline

#33 2011-04-07 14:39:32

jelle
Member
Registered: 2006-06-07
Posts: 165

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

Bloke wrote:

But one question: if you’d like to use it like that, why not just use <txp:output_form />?

Ah, my example was to demonstrate a feature I’d like to see. In reality I’m also using a lot of attributes.

I’m using smd_macro to setup and configure some jQuery plugins. In this case it’s Malsup’s excellent Cycle plugin Cycle allow for a lot of customization, as you can see here

My macro sets up the javascript and fills in the defaults (which I can override when calling the macro).

The macro also setup a div with an ID which the jQuery will target. Inside that div I need some material to be “cycled”. Ofcourse I can just setup the right txp:article or txp:image tags inside my macro. But I thought I’d try to use txp:yield to keep my webdesign and macro seperate. Next time I’d might not need articles/images but something completly different. The macro itself would look something like this:

<{wraptag} id="{id}">

   <txp:yield/>

</{wraptag}>

<script>
/* setup/config javascript cycle for this div#id */
</script>

So now I'd need just one tag/macro to setup my slideshow and I don't even have to edit my javascript. 

<txp:cycle wraptag="div" id="slideshow">
  <img src="file1"/>
  <img src="file2"/>
  etc.
</txp:cycle> 

Anywho…that was just the thought. I guess theres 100 ways to achieve the thing I’m trying here, but smd_macro seems so suited for the job to me. :)
thanks again.

Last edited by jelle (2011-04-07 14:43:13)

Offline

#34 2011-04-07 18:57:52

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

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

jelle wrote:

In reality I’m also using a lot of attributes.

I can see where you’re coming from. Container support woud be great. In the meantime a quick hack might be to add one attribute called {content} to your macro which you’d put in place of the <txp:yield /> in your example, and then perhaps do this:

<txp:variable name="content">
   <img src="file1" />
   <img src="file2" />
   ...
</txp:variable>

And then:

<txp:cycle wraptag="div" id="slideshow" content='<txp:variable name="content" />' />

Not uber-pretty but it achieves the separation.

Last edited by Bloke (2011-04-07 18:58:29)


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

#35 2011-04-08 08:51:16

jelle
Member
Registered: 2006-06-07
Posts: 165

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

Ah, isn’t txp amazing! I didn’t know variables could be containers…i’ve been using the value attribute all this time :)

Thanks again.

Offline

#36 2011-04-09 19:00:41

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

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

I think we should have a designated place where we could all share useful and somewhat general macros.

Offline

Board footer

Powered by FluxBB