Jump to content
adrian

Dynamic Description & Notes

Recommended Posts

I have been using this module for a long time and it's been incredibly useful so I thought it was time to share.

It's great for fields where you want to instruct content creators to reference something about a the page, its template, or its parent, or grand parent, etc

Specify fields/properties of the page in your field's Description or Notes content, eg:
[page.parent.url]
[page.title]
[page.template.label]

You can also define a str_replace to be performed on the returned value, eg: [page.name.(-|_)]
which will return the page name with the dashes replaced with underscores.

You can also use hanna codes within your description and notes fields - big thanks to @Robin S for this idea.

http://modules.processwire.com/modules/dynamic-description-notes/

https://github.com/adrianbj/DynamicDescriptionNotes/

Hope you find it useful.

  • Like 15

Share this post


Link to post
Share on other sites

Another possible use of this is pointing the user to edit another related page by making use of the ID of the related page, eg:

Test link to [Edit Parent](./?id=[page.parent.id])

which looks something like this:

Screen Shot 2016-10-05 at 7.57.14 AM.png

Anyway, there are lots of possibilities for enhancing the content of your Description and Notes text.

  • Like 7

Share this post


Link to post
Share on other sites

Thanks for sharing Adrian!

Is it possible to display values from an other language than the default? I would like to inject [page.url] and its counterparts from the other languages into the Title description of a blog page (just what we see in red on the Settings tab, but) it could be a good overview to see something like:

  • /blog/my-nice-article/
  • /es/blog/mi-buen-articulo/

I'm willing to hardcode the language IDs into it... :)

Another question: what about "custom" php? Or is it out of the scope of the module, because if it is "custom", why not implement it from scratch in the first place? :D 

  • Like 2

Share this post


Link to post
Share on other sites
1 minute ago, szabesz said:

Thanks for sharing Adrian!

Is it possible to display values from an other language than the default? I would like to inject [page.url] and its counterparts from the other languages into the Title description of a blog page (just what we see in red on the Settings tab, but) it could be a good overview to see something like:

  • /blog/my-nice-article/
  • /es/blog/mi-buen-articulo/

I'm willing to hardcode the language IDs into it... :)

Another question: what about "custom" php? Or is it out of the scope of the module, because if it is "custom", why not implement it from scratch in the first place? :D 

I knew I shouldn't have shared this module :)

Let me have a think about these and see what the best options might be.

 

  • Like 3

Share this post


Link to post
Share on other sites

@szabesz - I just did a little thinking about this.

I know this isn't what you want, but I wanted to clarify that the module does already correctly display field values in the language of the user.

Unfortunately I don't really think it's feasible for this module to handle outputting multiple versions of something in different languages. Same goes for custom PHP - that would go against Ryan's desire for the description and note fields to be Markdown driven. 

I actually think you should be able to achieve what you are looking for using @kongondo's awesome RuntimeMarkup module. I use it in a lot of situations where I need more complex info for guiding clients. I know it doesn't output directly in the title description like you wanted, but you could place this directly below and it would almost be the same.

Hope that sounds reasonable to you.

  • Like 1

Share this post


Link to post
Share on other sites

Thanks Adrian! It was just an idea I wanted to share but not really a feature request or so. And also thanks for reminding me of the RuntimeMarkup module!

  • Like 1

Share this post


Link to post
Share on other sites
On 6/10/2016 at 4:28 AM, szabesz said:

Another question: what about "custom" php? Or is it out of the scope of the module, because if it is "custom", why not implement it from scratch in the first place? :D 

@szabesz - I had a play around to see how you could use custom PHP replacements in the description field. My first thought was create a module where you define tag/code pairs in the module config, then look for and replace those in descriptions. This works, but requires the use of eval() and conventional wisdom is that eval() is evil. :biggrin:

So my next thought was Hanna Code, and this seems to work great.

In ready.php (or create an autoload module):

$this->addHookBefore('Inputfield::render', function($event) {
    if(!$this->wire('modules')->isInstalled('TextformatterHannaCode')) return;
    if(!($this->wire('process') && $this->wire('process')->className() == 'ProcessPageEdit')) return;
    $inputfield = $event->object;
    $description = $inputfield->description;
    if($description == '') return;
    $this->wire('modules')->TextformatterHannaCode->formatValue(new Page(), new Field(), $description);
    $inputfield->description = $description;
});

Then set up the Hanna codes you want to use in description fields. If you want to get the page object for the page being edited then add this at the top of your Hanna code...

if($process && $process->className() == 'ProcessPageEdit') {
    $p = $process->getPage();
} else {
    return "[Hanna code '$hanna->name' is not valid for this field]";
}
return $p->url; // an example to return the URL to the page without scheme and hostname

...then access the page object as $p

Edited by Robin S
Minor code changes
  • Like 7

Share this post


Link to post
Share on other sites

Nice @Robin S - I really ilke the Hanna Code approach - ultimate flexibility and so simple to implement!

 

 

  • Like 2

Share this post


Link to post
Share on other sites

I have something like this in mind:

[object_name separator selector separator property]

eg.

[pages::template=news,title*=rock::title]

If its an array, use the first item. Wouldn't this be more flexible?

Share this post


Link to post
Share on other sites

Thanks a lot @Robin S! Last night I went to bed and had a great sleep, and this morning when I wake up, reading your post I realize that my dreams came true :D

I will have time to try it out in the evening, but looks rather straighforward. I agree with @adrian, it is really smart to use Hanna Code. I hope that this thingy here is not an issue anymore and just left open for some reason and even if it is still an issue, your way of using Hanna Code is not affected by this.

 

  • Like 2

Share this post


Link to post
Share on other sites

@Robin S I have just find the time to try out your approch and since I like the Hanna Code module I will use it for sure.

On 10/7/2016 at 1:53 AM, Robin S said:

In ready.php (or create an autoload module):

I recommend updating your post at least with:

if(!$this->wire('modules')->isInstalled("TextformatterHannaCode")) return;

Just to make sure we never run into a fatal error.

Also for the sake of completeness, an example might be good to add in the Hanna Code itself:

return $p->url; // an example to return the URL to the page without scheme and hostname

Or something similar :) 

It would also be nice to add this to http://processwire-recipes.com/ but contribution to the PW Recipes sounds convoluted to me, so probably that is why it is not so popular among forum contributors. It's a pity though...

  • Like 2

Share this post


Link to post
Share on other sites

Hi everyone,

I have just updated this module to support insertion of Hanna codes, and renamed it to DynamicDescriptionNotes.

It passes the $page (for the current page being edited) and $field (for the $field where the Description or Notes text is referencing the Hanna code, so you can use $page and $hanna->field in your Hanna code to refer to these. This opens up lots of possibilities for dynamic content.

Please let me know if you have any problems or suggestions.

A big thank to @Robin S for the awesome idea!

PS, It's now available from the modules directory: http://modules.processwire.com/modules/dynamic-description-notes/

  • Like 6

Share this post


Link to post
Share on other sites

Hi Adrian, we've been using this very useful module intensively to comment fields for our customers, especially by the "allow-HTML"-option. Unfortunately, the support of HTML tags seems to be broken in version 0.1.0. Could you check this out, please?

Share this post


Link to post
Share on other sites
5 hours ago, xportde said:

Hi Adrian, we've been using this very useful module intensively to comment fields for our customers, especially by the "allow-HTML"-option. Unfortunately, the support of HTML tags seems to be broken in version 0.1.0. Could you check this out, please?

Glad you've found it so useful.

Sorry for the bug in that version. I have just committed a fix.

Please let me know if you have any other problems.

Share this post


Link to post
Share on other sites

Hi Adrian,

since 0.1.4, the support of HTML tags seems to be broken in fields of combined field types, e.g. FieldsetPage or Textareas. Could you check this out, please?

Thanks in advance,

Thomas.

Share this post


Link to post
Share on other sites

Hi @xportde - sorry about that. I have reverted those changes and taken a different approach to what I was trying to fix. FieldsetPage fields now work as expected, but there is still a problem with the individual fields under a textareas field, but I don't think that is related to the version of this module - I just don't think the Textareas module supports setting "entityEncodeText" to false, which is how this module allows html in the description. If I am correct in this assumption, then it is something Ryan will need to fix. Let me know your thoughts.

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...