Revolution: Selfaware chunks?

Created on 13 Jul 2015  路  9Comments  路  Source: modxcms/revolution

Just a quick idea

Can we add some default placeholders to getChunk with meta data like id and name?

Example:
To make debugging easier, I usually write my chunks like this:

<div data-chunk-id="1" data-chunk-name="hello world"  >
Hello World
</div>

This is helpful, but not always foolproof because you have to update name and id from time to time.

Writing it like this would make it easier:

<div data-chunk-id="[[+chunk_id]]" data-chunk-name="[[+chunk_name]]">
Hello World
</div>

Regards,

pepebe

area-core feature

Most helpful comment

To avoid possible conflicts, maybe stuff like that should go into a _self placeholder, like [[+_self.id]] and [[+_self.name]].

All 9 comments

Neat idea. I could see that being really useful.

I'm not ready for a pull request, but I'd like to post some code that would have to be changed to make chunks a bit smarter:

Line 486: core/model/modx/modparser.class.php

````
case '$':
$tagName= substr($tagName, 1 + $tokenOffset);
if ($element= $this->getElement('modChunk', $tagName)) {
$element->set('name', $tagName);
$element->setTag($outerTag);
$element->setCacheable($cacheable);

                    $tagPropString['chunkName'] = $tagName;
                    $tagPropString['chunkId'] = $element->get('id');

                    $elementOutput= $element->process($tagPropString);
                }
                break;

````

Now you can automatically add chunkName and/or chunkId to the chunkoutput:

screenshot 2017-01-30 19 22 10

The result:

screenshot 2017-01-30 19 20 52

Line : core/model/modx/modx.class.php

public function getChunk($chunkName, array $properties= array ()) { $output= ''; if ($this->getParser()) { $chunk= $this->parser->getElement('modChunk', $chunkName); if ($chunk instanceof modChunk) { $chunk->setCacheable(false); $properties['chunkName'] = $chunkName; $properties['chunkId'] = $chunk->get('id'); $output= $chunk->process($properties); } } return $output; }

Adding $debug, a new parameter for getChunk() would also be nice.

public function getChunk($chunkName, array $properties= array (), $debug = false) {}

Setting debug to something other than false (for example, comment or log) could help to track down performance problems.

Things that might be useful:

  • Cached on: 2016-12-12 20:34:12
  • Required processing time: 0.0153324s (easy).

I guess the caching related stuff is located around process(), right?

+10

To avoid possible conflicts, maybe stuff like that should go into a _self placeholder, like [[+_self.id]] and [[+_self.name]].

I think for other elements, for example, TV, similar behavior would be useful.

@pepebe You can send a PR to the branch 3.x with your decision?

@Ibochkarev Yes, I'll do that this week.

I'd like to combine this with issue https://github.com/modxcms/revolution/issues/14159. Would that be ok, or should we do one step after the other?

I'd like to combine this with issue https://github.com/modxcms/revolution/issues/14159. Would that be ok, or should we do one step after the other?

@pepebe sure, if needed it can always be split in multiple PRs 馃憤

Was this page helpful?
0 / 5 - 0 ratings