I'm having Stash issues when using stash:variables within channel entry conditionals.
template.html
{stash:embed name="pages" stash:paginate="y"}
pages.html
{exp:channel:entries channel="page" dynamic="no" limit="{stash:limit}" disable="categories|category_fields|member_data"}
<h2>{title}<h2>
{if '{stash:paginate}' == 'y'}
{!-- pagination code --}
{/if}
{/exp:channel:entries}
Setting a limit using {stash:limit} works great, but I can't seem to show/hide pagination using stash:paginate="y". Pagination seems to always show regardless of the stash variable.
I expect it's a parse order thing, your first var is working because its parsed properly and your second var is not being parsed before the exp:channel.
Try parse=inward on your exp:channel
I'm no master with stash yet but similar experience suggests parse order is in play
I used stash for the first time recently and it does take some getting used to. I found I had to use the Parse="inward" tag and be mindful of using "value" vs 'value' (single quote vs double quote). Little things like that made all the difference. Bottom line...parse order is one of the most important aspects of EE, yet I and many others don't understand well enough. That is my homework for today: parse order and all it's minutia.
Related
I have a loop of entries and I want to apply formatting to every second entry - not just applying a class but also some basic HTML markup. How can I do this?
This question seems to come up a lot so I thought I would post a simple example:
{exp:channel:entries channel="whatever"}
{switch="<div class='entry'>|"}
<h2>{title}</h2>
{if count != total_results}{switch="|</div>"}{/if}
{if count == total_results}</div>{/if}
{/exp:channel:entries}
In this example, a div with a class of "entry" is wrapped around every second entry. The switch variable at the front end is pretty straight forward. The back end uses two conditionals: if the entry is the last entry in the loop, close the DIV. If the entry is NOT the last entry in the loop, close the DIV only for every second entry (a reflection of the switch variable at the beginning of the loop).
Important to note here that the switch variable is very sensitive to quotes - so when inserting HTML in this fashion, inside the switch variable, you have to use single quotes rather than double quotes. This is fine for simple insertions, but may be a bit unfriendly if you have more complex formatting in mind. Hopefully this helps some folks and feel free to expand on this idea.
There is also a plugin which might help in this situation GWcode Alternate. I haven't used it myself as I prefer to use the native switch tag mentioned in the other answer.
The example I had used was specifically for those instances in which a DIV is not desired on EVERY entry but rather a wrapping DIV around certain intervals - common when you want to have a jQuery slider that includes 3 entries at a time, for example. This was expressly the purpose of my example. EVERY entry is not what I would consider intervals, which is what my example was intended for. Certainly it is an edge case - but an edge case that occurs often enough to capture a simple solution to the challenge that still uses native functionality with only simple conditionals.
<div id="temp_1333021214801">
<input type="text"/>
</div>
$browser.text_field(:xpath,".//*[#id='temp_1333018770709']/input").set("apple")
I am getting error "unable to locate element", because the ID changes dynamically.
Please help me to set the text in the text field.
It seems like your dynamic id is temp_ so this should do it given information above:
browser.div(:id, /temp_\d+/).text_field.set 'something'
Issues with my solution is that it assumes id will always be temp_ regex matching any number set consecutively, which seems to be the case with your sample above. Also, it assumes there is no other div(:id, /temp_\d+/) combination in the DOM of that page, most likely should not be an issue.
If you have dynamic IDs I can suggest the following:
Code to object counts. For example
$browser.text_field(:index => 2)
gives the third text_field on the page.
Code to what is around the thing you're trying to find.
$browser.div(:name => 'mydiv').text_field(:index=>2)
gives the third text field in the div called 'mydiv'.
HOWEVER
If your front-end is less-than-testable in this way I highly suggest you put time into thinking over your commitment to automated testing in the first place. Any minor change to the software is going to have you working until 9pm pulling your hair out and rocking back and forth as you update all your scripts, so unless code maintenance is your weekend hobby think about semi-automation or exploratory testing or manual scripts. Talk to development (whomever that might be. It might be you!) or the higher-ups (unless that's you too) to see if it can be made more testable. Also don't use xpaths unless you take some deviant pleasure in it.
Hope that was helpful, I can't do anything specific without the source HTML.
I have used Drupal and think I'm doing it wrong with EE. I want to create many blocks of embedded User created entries in some of the templates, but don't want to have to create a channel for each one. In Drupal I could create a block specific to the client's needs, but I'm stumped on how to do this in EE.
For example, I have three different content areas on the home page, top/middle and bottom. Client doesn't want to roll out blog entries, they want specific content put in each one. The only way I see is I'd need to create three different channels and embed as such for top, changing channel to middle and bottom for each block. Is there a better way?
{exp:channel:entries channel="top" disable="categories|member_data|pagination" limit="1"
sort="desc" dynamic="no" }
Would I use category group and categories to do this? Meaning, I would create top, middle and bottom categories to call out those entries in my "home" channel?
For less than 1 hour of billable work, you'll get hundreds if not thousands of hours of effort packaged up for you to run with. Someone always pays for code, why not you this time? :)
The solution you have found does work - but I've found that ultimately it does not offer the flexibility needed by many clients.
I've used the following solution for many sites and clients have been pleased with it.
1) Define your block data as channels. For example I often have a Sidbar Ad, Sidebar Scripts, and Sidebar text channels.
2) Use a playa field-type (or another relational field-type) to create relationships from a parent entry (a page) to theses sub content types.
This normally looks something like this on the backend:
3) You can now use the parent entry to display the sub content. You'll of course need to pull all this data into your templates with something like the following:
<div id="right-side">
{exp:playa:children}
{if channel_short_name == 'sidebar_javascript'}
{cf_sidebar_js}
{/if}
{if channel_short_name == 'sidebar_videos'}
{exp:channel_videos:videos entry_id="{entry_id}" embed_width="300" embed_height="238"}
<h4>{title}</h4>
{video:embed_code}
<p class="caption">{video:title}</p>
{/exp:channel_videos:videos}
{/if}
{if channel_short_name == 'sidebar_ads'}
{exp:adman:show group="{cf_sidebar_adman_block}" order="RANDOM" limit="{cf_sidebar_adman_block_number_of}"}
<a href="{ad_url}" target="_blank">
<img src="{ad_image}" alt="{ad_alt}" />
</a>
{/exp:adman:show}
{/if}
{/exp:playa:children}
</div>
We generally make a channel called something like "general content" with a single field that can have any kind of native formatting (none or xhtml would mostly be used) and then use it for one-off bits that don't fit into other channels. It's hard for the client to find these entries in the CP for editing, so we make front-end "edit" links that open the correct entry in the CP and are visible only to member groups with content editing permissions.
This will only get hairy if you really need multiple customized fields for this use.
I have never used Low Variables, but I am under the impression that it could be useful here.
While I agree with the posters talking about the value of add-ons, this is a particular need that I have never had any problem solving natively. Besides the issue of the cost of add-ons (which IMO is worthwhile) you also add complexity to your installation the more software you add to it, making it more time consuming to troubleshoot bugs and to upgrade EE.
I've been trying to make something visible only on certain entry_id in expressionengine
{if entry_id="33"}
... show certain content
{/if}
is this even possible in eemcs?
thanks
Sure - but you need to use the {entry_id} variable within a tag pair that provides that variable. For example within a {exp:channel:entires} tag pair.
If you're using url_titles in the URI you may want to think about using segment variables instead. For example:
{if segment_2 == "blog-post"} You're on a blog post{if}
This is what's referred to as a simple conditional in EE, and it's fast enough.
One very important thing to remember in EE is that the standard if:else/else:if routine of an advanced conditional can be very slow, primarily because EE renders all of the code segments and then works its if:else magic. If you find yourself testing many ids or groups, this slows the site down proportionally. In fact, sometimes EEs parse order can stop if:else from functioning entirely.
Instead, consider Mark Croxton's Switchee, a fantastic free plugin that lets you have as many conditions, even nested conditions, without slowdown. It parses just the conditions, then when triggered, is smart enough to descend and run the right code segment:
I know this sounds crazy, but I need to show some post information outside of the loop in the expression engine channel module. Is this possible?
You could use EE's SQL Query template tags (if you know, or have access to the database table names and know what to look for in the database):
http://expressionengine.com/user_guide/modules/query/index.html
Basically, you'd output only what you need - it doesn't have to belong to a channel, or anything specific. The one kicker is that you'd have to know the basics of SQL syntax, but if you have a small working knowledge of it, you can do tons of additional things with it.
If you're not keen on SQL, you could simply embed a template within the template that you're working on. Here's a simple example that assumes you're editing the index and meta templates inside of a template group called 'news':
index template contents:
{exp:channel:entries channel="news"}
<div class="entry">
<h1>{title}</h1>
<div class="content">{body}</div>
{embed="news/meta" this_entry_id="{entry_id}"}
</div>
{/exp:channel:entries}
meta template contents:
{exp:channel:entries channel="news" dynamic="no" limit="1" entry_id="{embed:this_entry_id}"}
<div class="meta">
<p>{entry_date}</p>
<p>{author}</p>
</div>
{/exp:channel:entries}
As you can see, the index template is embedding the meta template. Note that we're passing a parameter to the meta template so that it knows which entry ID to print information about. If you're unfamiliar with EE's template embedding feature, you can read more about it in the EE docs. Embedding templates in other templates is a great way to access the {exp:channel:entries} loop multiple times.
There's an add-on called MX Jumper that allows you to "set" a variable from inside your entries loop and then "get" it elsewhere in the template (before or after in the HTML loop doesn't matter because it parses later).
Alternatively, the approach that's all the rage now is to use the add-on Stash to store any and all elements you need to use distinctly as stash variables that you set and then get - similar to the above, except that once you set them, getting them has to happen at a later parsing stage. The beauty of this approach is stash will store the "set" variables for reuse either at a user or site level, and you can determine what the expiry period is - which then results in better performance. When you apply this broadly using the "template partials" mindset, you can store everything with stash, and then call them into a small number of wrapper templates. This makes it possible to use stash to set, for example, your entry title, then get it three separate times in the wrapper template without any additional load - no need for separate loops within your template - one loop to set the variable, and then you can call that variable as needed in your template - it's kind of like creating global variables on the fly.
I would also suggest looking at Stash.