Expression Engine - Pass loop variable into embeded template - expressionengine

have some trouble with Expression Engine variable passing in templates.
There is some piece of code:
// query:
{exp:channel:entries
channel="static"
}
// repeating field in a loop
{content_matrix}
<div>
{text_cell}
</div>
{image}
{/content_matrix}
//
{/exp:channel:entries}
I want to move content_matrix field with big inner HTML (example is shorter) sctructure into separate embed template for reusage in other templates.
Tried to build such embed but it doesnt work:
{embed="incl/content_matrix" matrix="{content_matrix}"}
And body of smaller template:
{embed:matrix}
<div>
{text_cell}
</div>
{image}
{/embed:matrix}
In this way it works if you passing single element, like ID, but not for mupltiple element.
Maybe it needs to pass entire entry.
How it can be done?
Thanks.

Have you considered using the Stash add-on?
I imagine you can stash the matrix content dividing between different parts of your html with some kind of separator, then in the embedded template wrap a search/replace for the separators with the proper html around the grabbed stash.
It might be less of a pain to write a quick, custom plugin, though.

Embed variables pass parsed output, not tags. So in your example:
{embed="incl/content_matrix" matrix="{content_matrix}"}
What you're actually passing in the matrix parameter is the full HTML table output of the data in that particular entry (since Matrix fields output a table when used as a single tag).
I think what you actually want to use to prevent repeating yourself is a Snippet. So just make a snippet containing:
{content_matrix}
<div>
{text_cell}
</div>
{image}
{/content_matrix}
And save it as, say, matrix_loop. Then include it inside your Channel Entries loop like so:
{matrix_loop}

Related

Extract multiple image links from a single div tag that has no class name

Hi I have this HTML code from a website: I want to be able to extract multiple images, I have cases where there is 3-4 images. How would I go about doing that?
<div style="float: right;"><u>Chakra required:</u>
<img src="https://naruto-arena.net/images/energy/energy_2.gif">
<img src="https://naruto-arena.net/images/energy/energy_4.gif">
</div>
My code:
chakras1 = soup.find_all("div")[42].img['src']
print(chakras1)
Result:
https://naruto-arena.net/images/energy/energy_2.gif
I only get the FIRST image but now the second one.
To extract multiple images from within a tag, I personally stick to using for loops. So what I mean is once you find the div tag that you want to look within and say you call that chakras1, I would write the following:
for img in chakras1.find_all("img"):
print(img)
For me the steps kind of go as follows:
find the specific tags you are looking for (img src)
see what tag those tags are within (
navigate through the HTML to that tag (using beautiful soup's .find or .find_all functions depending on what you want to use)
once you have navigated to the tag search within that tag for the tags you're really looking for.
One quick note, with this method, if you are looking through multiple div tags, you're also going to need to loop through those as well.
I hope this makes sense!

Expression Engine entry_id Parse

Hey Everyone I am having a huge problem :
I have this Line :
{exp:entries:ids_assigned_to_me tag="idont" channel="proiecte" field="clienti"}
Which outputs me some entry ids
and i can put it There at the entry_id:
{exp:channel:entries channel="proiecte" entry_id=" HERE " }
{content}
{/exp:channel:entries}
I tryied and search for hours over forums and stuff, but variable, snippets and embeding and stuff doesen't seemed to work out. Any Ideas ? about Inward Parse or something ?
Also tried php but didn't worked out :((
You're using the entries add-on and by the looks of it you're using the single tag method. It's not clear from the documentation, but I think as you're specifying a single tag, it's outputting the IDs, but if you use it as a tag pair (as other examples in the documentation show) and this piece of documentation hints at: "If no entries are assigned the logged in member, the no_results conditional is returned.".
So first try
{exp:entries:ids_assigned_to_me tag="idont" channel="proiecte" field="clienti"}
{content}
{/exp:entries:ids_assigned_to_me}
...all by itself without any {exp:channel:entries} tags. No idea what "tag" parameter is doing in there.
If that doesn't work and that method doesn't support a tag pair, then you'll need to do as an embed across 2 templates:
1st template:
{embed=template-group/second-template entry_ids="{exp:entries:ids_assigned_to_me tag="idont" channel="proiecte" field="clienti"}"}
2nd template:
{exp:channel:entries channel="proiecte" entry_id="{embed:entry_ids}"}
{content}
{/exp:channel:entries}

URL title to Entry ID on Channel Entries tag

I'm trying to use the "URL title to Entry ID" plugin to feed the entry_id parameter into a Channel Entries tag, but can't figure out a way to get the ID information inserted early enough in the template parsing order.
This doesn't work - it picks up no entry ID, and so displays all entries:
{exp:channel:entries entry_id="{exp:url_title_to_entry_id parse="inward" url_title="{last_segment}"}" dynamic="no"}
{title}
{/exp:channel:entries}
Any suggestions would be much appreciated.
You can't have a function tag as a parameter to another function tag.
So either you have to pass the {exp:url_title_to_entry_id} result as an embed variable to another template that holds the channel:entries tag, or you have to use tag pairs so that one function tag, wraps the other and uses variables.
url_title_to_entry_id doesn't allow for tag pair, so either use the embed technique, or use another add-on.
BUT, you don't need the add-on at all...
{exp:channel:entries url_title="{last_segment}" dynamic="no"}
{title}
{/exp:channel:entries}
reference.
I'd also suggest added required_entry="yes" and limit="1" and then add {if no_results}...{/if} conditional inside. This will prevent it outputting all entries if it can't find a match.

Passing entry_ids to channel:entries tag with low variables entries select

I'm trying to pass entry_ids to a channel entries tag using low variables entry_select. When i place the following tag by itself in a template it outputs a list of 3 pipe separated entry_ids: {exp:low_variables:single var='lv-home-groups'}
however when I add the same code to the following channel:entries tag nothing is output.
{exp:channel:entries channel="groups" entry_id="{exp:low_variables:single var='lv-home-groups'}" disable="category_fields|pagination"}
code here
{/exp:channel:entries}
I've tried early and late parsing but can't get it to work. If i manually place the entry_ids it works fine. I'm trying to avoid using an embedded template for performance reasons.
Here's how: make sure early parsing is enabled for that variable, and then use the variable syntax instead of the tag syntax:
{exp:channel:entries channel="groups" entry_id="{lv-home-groups}"}
code here
{/exp:channel:entries}

modx create layout with chunk and call with template

I'm using modx revolution. I'd like to create a chunk called layout that calls other chucks example
Head
header
nav
body
footer
then in my template do something like //open layout tag[[$layout]] [[$layout]]//close layout tag. then inside of the the open close tags append my [[*content]]. this would allow me to reuse my layout template over and over again without having to replicate it in the templates. First question, is it possible, second what kind of syntax would be needed to achieve this goal? I'm rather new to modx and know it's possible with other frameworks, so any help would be appreciated. Thanks.
Sample concept done in Apache Tapestry framework, obviously different syntax, but should give you the general idea of what I'm looking for.
components/Chunks used.
Layout
Header
Nav
Footer
Inside of layout
<html>
<t:Header/>
<t:Nav/>
<t:Body/>
<t:Footer/>
</html>
Inside of Index/Template
<t:Layout>
template body content goes here ex. [[*content]]
</t:Layout>
Hope this helps to clarify.
Your post is not very clear and I think you haven't really taken much time to read up on how MODx works before looking for help.
That aside, I think what you want to do is create different templates, structured more or less like this:
[[$header]]
[[$nav]]
<div id="content">
<h1>[[*pagetitle]]</h1>
[[*content]]
</div>
[[$footer]]
That might do for your home page, then for internal pages where the layout is a bit different you can create one or more new templates for each layout:
[[$header]]
[[$nav]]
<div id="content">
<h1>[[*pagetitle]]</h1>
[[*content]]
</div>
[[$sidebar-chunk]]
[[$footer]]
You can even show different layouts using a single template something like this:
[[$header]]
[[$nav]]
<div id="content">
<h1>[[*pagetitle]]</h1>
[[*content]]
</div>
[[*parent:is=`6`:then=`
[[$recent-articles]]
`:else=`
[[$sidebar-chunk]]
`]]
[[$footer]]
That should get you started, but you'll soon realise there are multiple ways to do everything in MODx.
You can put your [[*content]] where-ever you want, even inside another chunk, if that's what you mean.
So your [[$layout]] chunk could just be this:
[[$header]]
[[$menu]]
<div id="content">
<h1>[[*pagetitle]]</h1>
[[*content]]
</div>
If you want to make some minor changes in a chunk on a template-basis you could also do something like this in the template:
[[$layout? &customContentBits=`
<h1>[[*pagetitle]]</h1>
[[*content]]
`]]
and your layout chunk could then be something like this:
[[$header]]
[[$menu]]
<div id="content">
[[+customContentBits]]
</div>
That's a placeholder ([[+customContentBits]]) which is set by adding the &customContentBits in the chunk call.
Explained that a tad more with a different use case on my blog some time ago too: http://www.markhamstra.com/modx-blog/2010/10/introducing-element-properties-and-output-modifier/
What you are asking can absolutely be done. In fact, on my website, I even have the same template/chunk combo providing multiple layouts by passing a template variable as a chunk modifier. But anyhow, let's keep things simple.
A quick note on your question., ModX doesn't use start tags and end tags, natively. It's best to stop thinking that way. Instead just place things where you want to place them. Resource variables can go in any chunk, as each resource is unique.
Create your Chunks:
First, start with the simple ones. Create your Header, Footer, and Navigation. Next, create your Body. Inside the Body, make sure to include your [[*content]] (no... it doesn't have to go into the Template. Finally, create your Layout with the following code:
[[$header]]
[[$navigation]]
[[$body]]
[[$footer]]
Create your Template:
Your template can now be as simple as [[$layout]]. You're done.
Note
While you can do this with ModX, understand that the power of ModX is that you can have multiple templates and chunks depending on the type of content you have. Singularizing everything like this really takes away a major advantage of using the platform.
Mark Hamstra more or less gave you the answer, but just to clarify: Any snippet, chunk or output of some sort in Modx can take parameters. Chunks and snippets especially can make use of these params easily. From what i understand you want to have all your templates call [[$layout]] and nothing else.
The layout chunk in turn looks like
[[$header]]
[[$navigation]]
[[$body]]
[[$footer]]
On this you simply build and add your params, nesting them down from the top like
[[$layout? &useNavigation=`1`]]
(And continue passing the param in your layout chunk)
[[$header]]
[[+useNavigation:is=`1`:then=`[[$navigation]]`]]
[[$body]]
[[$footer]]
Another way of accomplishing the same behaviour would be to use a single template to which you have connected a series of template variables that decide how the template looks like. You might have template variable called useNavigation of checkbox type. If you check this through the resource editor it will be passed to your $layout chunk directly without having to add params into the $layout chunk call.
[[$layout]]
(Just call layout normally and add the TV checks to the layout chunk directly.
Note the difference between calling a TV and a placeholder, + vs *)
[[$header]]
[[*useNavigation:is=`1`:then=`[[$navigation]]`]]
[[$body]]
[[$footer]]

Resources