Textpattern Forum

You are not logged in. Register | Login | Help

#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: 5,811
Website

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.

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: 5,811
Website

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.

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
Moderator
From: Walla Walla
Registered: 2004-11-19
Posts: 2,050
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

#37 2011-04-10 00:06:28

jstubbs
Moderator
From: Hong Kong
Registered: 2004-12-13
Posts: 2,179
Website

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

Some tutorials or tips would be helpful for users in the usual place.


TXP Tips | @txptips | Me | @jonathanstubbs | Github

TXP Builders – finely-crafted code, design and txp @txpbuilders

Offline

#38 2011-04-10 16:52:10

jcd
Member
Registered: 2010-04-15
Posts: 12

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

Thanks for this amazing plugin! I have recently used it to make it easier for clients to insert an image gallery. The macro passes on the image IDs to smd_gallery, which then creates an unordered list with the images.
Upon validating the HTML, I found the problem that Textpattern / Textile always adds a <p></p> container around the code generated by the macro. This of course doesn’t validate if the macro inserts a block element like <ul> or <div>. I know you can just put a space in front of the macro call in the Textpattern article, but I think that’s not an elegant solution for the client. Is it somehow possible that smd_macro can avoid being surrounded by the <p> tag?

Offline

#39 2011-04-10 19:34:38

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 5,811
Website

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

jcd wrote:

Is it somehow possible that smd_macro can avoid being surrounded by the <p> tag?

Ummm, ahhhh, errrr… that’s a good point. I can’t think of a neat way offhand. The usual techniques (turn off textile, use notextile. start line with spaces, or surround tags with == signs) are, as you say, not exactly client friendly or have some shortcomings in terms of functionality.

The thing is I don’t think there’s anything smd_macros itself can do to guard against this because it just does what the macro tells it to do and the Textile parser does the rest ‘outside’ the macro’s output. The only cheating way I can think of is adding a line of jQuery to the end of your macro (or write a separate macro that you call somewhere else on your page that injects the jQuery) which scans the DOM tree for, say, the class or ID of your container and performs an unwrap on it.

That technique might have some shortcomings:

  1. it probably won’t help the validator because the manipulation is done post-DOMready but it might make you feel better that you know it is actually valid :-)
  2. you may need to guard against those situations where a client willfully or accidentally puts a space in front of the tag or is otherwise Textile-savvy; in those instances you might end up removing the whole article container (or <body>!) so you may require some defensive programming to check you’re only unwrapping paragraph markers

Aside from that I’m out of ideas, sorry. Some other TXP fox might come up with something more cunning though.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern.

Txp Builders – finely-crafted code, design and Txp

Offline

#40 2011-04-10 21:07:13

jakob
Moderator
From: Germany
Registered: 2005-01-20
Posts: 1,895
Website

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

How about using pax_grep or a snippet of php in your smd_macro to remove the <p> and </p> from the output as outline here? That would happen server-side prior to code output.

Last edited by jakob (2011-04-10 21:07:31)


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB