Chunk only working in template and not in resource content

Summary

Basically, I have a chunk written for my modx site that will only show if I add it to a template element and not when I add it to the content of a resource (using that same template element as it’s template).
Is there any reason (or number of reasons) that this could be happening, and any possible solutions?

This is the chunk:
[[$articleThumb? &imageLink=http://www.google.com &thumbText=THIS IS TEST TEXT FOR AN ARTICLE HEADER]]

Thanks in advance for any help.

Step to reproduce

The chunk basically refers to code for a thumbnail for a listing of articles.
The chunk is:
[[$articleThumb? &imageLink=http://www.google.com &thumbText=THIS IS TEST TEXT FOR AN ARTICLE HEADER]]

Observed behavior

As I said, it works perfectly if added to the template but not when added to the content section of any resource instead.

Expected behavior

I expected that it works in resources too?

Environment

Only joined MODX like a week ago so I assume it is the most recent version. - Installed from softaculous.

If I understand you correctly I’m guessing the reason this is not working is because the content field of a resource is not parsed the same way as the chunk within a template would be.

I also don’t think you’re supposed to input chunks through the resource. Afaik the proper way to insert content into a template should be TVs.

Why do you want to add it to a resource?

1 Like

Hey, cheers for the reply.

The simple answer may just be a lack of understanding MODX but the idea behind it was basically to call a chunk from inside the resource that represents a thumbnail for an article listing page and then to repeat the chunk with different options. – This does work perfectly in the template but not the resource. – It was in an effort to quickly update a page and move thumbs to Page2/3/4/etc… without using things like Articles or Blogit, as I do not like them. I want a slightly more hard-coded approach to the site. I understand that involves a little more effort, hence creating the chunk to take a little of the workload off.

Hope that explains it. As I said it may just be a lack of understanding. – If you know a way that I can do this with TVs multiple times on a single page. That would be great.

Thanks agan.

So I’m still not sure if I really get want you want to do but if you’re trying to put the same thing multiple times on a page with different values I would use MIGX. MIGX gives you the ability to process multiple inputs as one TV:

  1. install MIGX through the manager under Extras -> Installer
  2. create a new TV, let’s name it articleThumb and select migx under input options
  3. also under input options there’s now Form Tabs. Here we define which Input fields you’ll later have to fill with different values. If you want to be able to edit the &imageLink and the &thumbText individually you want to have this code in there. (Note that I named the fields in this example like your attributes but you can choose whatever name you like as long as you are consistent in the upcoming steps with it):
[
{"caption":"Variables", "fields": [
    {"field":"imageLink","caption":"Image Link"},
    {"field":"thumbText","caption":"Article Header"}
]}
]
  1. Now we fill the Grid Columns field to set the layout for our table (this will make sense later):
[
{"header": "Image Link", "width": "100", "sortable": "true", "dataIndex": "imageLink"},
{"header": "Article Header", "width": "100", "sortable": "true", "dataIndex": "thumbText"}
]
  1. Under Template Access, give this TV now access to the template where you’ll use it on later.
  2. Next step is to create a new chunk (for your chunk) to use it as a MIGX template, let’s call it articleThumbTpl and connect it with our MIGX variables like so:
[[$articleThumb? &imageLink=`[[+imageLink]]` &thumbText=`[[+thumbText]]`]]
  1. Now head over to your template where you want your Thumbnails to appear and call our MIGX TV:
[[getImageList? 
   &tvname=`articleThumb`
   &tpl=`articleThumbTpl`]]
  1. If you go now to your resource under Template Variables you should see an empty table somewhere. (Remember the table part in step 4?) Now press Add Item and fill in your values. You can add how many instances of this as you like this way.
  2. After saving you should see all the instances you added on the front end.

I hope this helps, if you’re stuck at some point feel free to ask or also go through the MIGX Docs as there is also a really good explanation.

2 Likes

Thanks man, you have been incredibly helpful.

Quick question before I go and try it:

Will I be able to easily Shift the thumbs down as I add new ones and paginate (or at least imitate pagination) by numerically shifting them down the list and onto another page?

Thanks again.

1 Like

Yes, you can easily (even by drag and drop) sort the entries in the table.

As far as pagination goes, I’m not sure though how you can achieve this without having multiple MIGX TVs and an unfortunate amount of manual work editing them. This exceeds my knowledge atm, sorry.

I’m sure it’s possible some way as MODX is incredible powerful, but maybe someone else is able to help out in that aspect.

I know that you didn’t want to use Articles (and honestly it can be frustrating to find things sometimes) but as far as pagination goes, that’s very easy to implement :wink:

2 Likes

WOW… So, I am an idiot, apparently. – I appreciate your help a lot and just in case anyone out has made the same error as me, I will put below the simple problem (And good reason to always double check everything) that had caused the chunks not to appear in the resource:

REASON: During editing and moving the chunks from the template to the resource…

*I had accidentally deleted the [[content]] tag from my template.

Yes, it was that simple. – I would have saved like 5 hours if I had just checked.

Well, ya live and ya learn, I suppose. Haha.

Cheers again. – Hope that helps someone.

2 Likes

I thought about asking that yesterday, but held back… >1hr means start sanity checks, lol

1 Like

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.