craftsmancoding / assetmanager

Asset Manager for MODX Revolution
36 stars 15 forks source link

Use with getResources #26

Closed crecorn closed 10 years ago

crecorn commented 10 years ago

I'm unable to get this to work. I'm using getResources in my template to call child resourses. Each resource has asset in a group called icon. How would I call that asset in my getResources tpl?

This was my last attempt:

<div id="homejump" class="qrt columns">
<div id="icon">
[[Asset? &asset_id=`[[+asset_id]]` &group=`icon`
    &tpl=`<img src="[[+url]]"/>`  
]]
</div>
[[+content]]
</div>
fireproofsocks commented 10 years ago

What's your getResources call look like? And which version of MODX and which version of the Asset Manager are you using?

The inline formatting chunks have been problematic (I've been unable to work around some of the default MODX parser behaviors). I would try using a traditional chunk for your Asset snippet's &tpl parameter and calling it in your snippet, e.g. &tpl=myChunkHere

crecorn commented 10 years ago

MODX v2.3.1

[[getResources? &parents=`27`&tpl=`homejump` &limit=`0` 
&includeContent=`1` &includeTVs=`1` &processTVs=`1` &tvPrefix=``]]

homejump chunk is where that previous code is. I add the TVs because I thought is might be need to process the assets.

fireproofsocks commented 10 years ago

Wait a minute... you can't just arbitrarily print out an asset without providing the asset id. What asset should be fetched? getResources knows nothing about the asset id because it's not a TV value. I think you should be using the getPageAssets Snippet instead: https://github.com/craftsmancoding/assetmanager/wiki/getPageAssets

That will loop over any assets assigned to the current page.

You're also using invalid arguments... the Asset snippet doesn't support the &group argument, only the getPageAssets does.

If you're trying to show all assets assigned to all resources returned by getResources, you'd need to try something like this:

[[getPageAssets? &page_id=`[[+id]]` &group=`icon` &innterTpl=`myChunkHere` ]]

And then put your formatting info into the myChunkHere:

<img src="[[+Asset.url]]"/>

So the "id" placeholder would get populated by getResources, and then the getPageAssets Snippet would know which assets to retrieve.

crecorn commented 10 years ago

No dice. It's just blank. The img html template is not called.

fireproofsocks commented 10 years ago

I can't reproduce this. I added a verbose example to the docs showing one way to do this.

I would recommend you first ensure that your getResources call is returning the pages you want. Then on a separate page, try calling the getPageAssets snippet passing it one of the page_ids hardcoded so you know that it is fetching the page assets the way you expect.

https://github.com/craftsmancoding/assetmanager/wiki/getPageAssets

fireproofsocks commented 10 years ago

Ah -- just spotted a typo.... you put "&innterTpl", but it needs to be "&innerTpl" -does that help?

crecorn commented 10 years ago

Aaaargh Typos!

It works when I do this:

[[getPageAssets? &page_id=`[[+id]]` &group=`icon` &innerTpl=`<img src="[[+Asset.url]]"/>` ]]

If I use &InnerTpl=iconasset and setup a chunk it returns "Iconasset" on the page.

But hey we got it working.

crecorn commented 10 years ago

It wrap the image in a ul tag. Any way to prevent that?

fireproofsocks commented 10 years ago

Glad it worked -- re "iconasset", that looks like another typo with capitalization? "iconasset" vs. "Iconasset"?.

Re the ul tag, set the &outerTpl to blank -- its default value is a list wrap. See https://github.com/craftsmancoding/assetmanager/wiki/getPageAssets