Jump to content

InputfieldTagReplacer


bernhard
 Share

Recommended Posts

What it does:

you can easily define replacement-tags in your fields (also descriptions) like this:

[demo] => '<span class="demo">some demo markup</span>',
[demo2] => '<span class="demo">some other demo markup</span>',
[demo3] => '<span class="demo">one more demo markup with a <a href="#" class="pw-modal">modal link</a>!</span>',

Screenshot:

post-2137-0-38793200-1445094351_thumb.pn

Why?

today i had to (to be more precise: i wanted to) have a link in one of my field-descriptions that opened a modal to a list of icons...

post-2137-0-75123800-1445093685_thumb.gi

basically i just wanted to add a "pw-modal" class to the link what is not possible through markdown [link](http://example.com)

post-2137-0-70407500-1445093931_thumb.pn

i ended up with the following little module:

// removed - please see the code on github

its also on github: https://github.com/BernhardBaumrock/ProcessWireModules/blob/master/InputfieldTagReplacer.module

i know but didn't use RuntimeMarkup because i wanted the link in the description not in a separate field!

Questions:

  • would it be possible to get the currently edited $page somehow? the $page object i get now is the admin page with the according process.
    it would be nice to be able to do things like $page->parent or the like...
  • would there be another method to hook into that would be more efficient or better in any other way?
  • how can i debug the $event object?
    i tried var_dump($event); die(); but that showed nothing
    var_dump($event->return); die(); shows the form/field markup
  • would there have been an easier way to achieve this?
  • Like 4
Link to comment
Share on other sites

Questions:

  • would it be possible to get the currently edited $page somehow? the $page object i get now is the admin page with the according process.

    it would be nice to be able to do things like $page->parent or the like...

$process = $this->wire('process'); 
if($process && $process->className() == 'ProcessPageEdit') $page = $process->getPage();
  • Like 3
Link to comment
Share on other sites

  • 1 year later...

if found this module to be useful for enriching the field descriptions, in the most recent case i needed to output the page ID, and the full url to the frontend page, and did it by using this; not sure if there is any other easier way of parsing tokens in the field descriptions at this stage, this was the only way i could figure out how to do it.

Link to comment
Share on other sites

hi @Macrura

glad you like it, but to be honest i don't think any more that this module has a big value :-[  now as i've done a lot more modules on my own, i would just put a simple hook into ready.php and hardcode the description. or get the description from a field in a custom settings page or the like...

  • Like 1
Link to comment
Share on other sites

right - yeah, i'm not actually using the module, just the function which is in my generic site utilities module;

using this replacer method (as opposed to hardcode) though allows you to have a few frequently used replacements in a lot of fields, e.g:

page.id
page.httpUrl

etc..
 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...