How to embed blocks of data in ExpressionEngine without using many channels - expressionengine

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.

Related

Use liferay-ui:asset-categories-selector tag to offer one vocabulary only

I'm developing a Liferay portlet supposed to offer a way of categorizing its content. I created multiple vocabularies (e.g. frogs, apes, birds).
In the view of THIS portlet I want to offer the categories of the "frogs"-vocabulary only. I know I could write some code to read the categories contained in the vocabulary to offer them in a combo-box.
But, isn't there a way of convincing the built-in liferay-ui:asset-categories-selector-tag to show one vocabulary only? Or may be there's some other tag? (I'm stuck here.)
Here's my current code that lists all vocabularies:
<liferay-ui:asset-categories-selector
className=" <%= JournalArticle.class.getName() %>"
/>
Unfortunately this taglib's documentation is quite tumbleweed. You might need to look into the implementation for the actual content of the attribute, but curCategoryIds might be a good choice to start trying out if this is foreseen.
Alternatively it might be worth creating another tag (based on this one, in a new taglib) - if you do this, you might want to file an issue or feature request and contribute it back into the liferay-ui taglib.

Display all categories from one site and only a specific category from another site in Expression Engine MSM

I'm using ExpressionEngine's multisite manager and I'm displaying channel entries from two of the sites - our global site and our localized site for our Australia office. For the Australia site I would like to display all channel entries, but from the Global Site channel entries I would like to only display channel entries from a particular category (in this case "25" ie. those tagged as pertaining to Australia on our Global site).
If I use something like this below, it wont show the any of the entries from the Australia site (tpi_au) because I don't have those categorize.
{exp:channel:entries channel="success" dynamic="no" site="tpi_hq|tpi_au" category="25"}
Is there a way to make that category="25" apply only to tpi_hq?
Sorry this is probably a really easy answer or I'm just doing something totally wrong to begin with... :/
Thank you!
I don't believe there is a way to do this directly in a single channel call.
Situations like this arise all the time, not just with MSM. What if you want 10 entries for category X and 7 entries from category Y? Same deal.
Basically you need to make two channel:entries calls.
If you don't care about the order of the entries you are done. If it bothers you that the tpi_hq entries are always at the top of the list while the tpi_au entry is always at the bottom then you need to figure a way to sort them.
Two approaches I've used for this:
Sort the entries on the client side. I've done this in jQuery using html5 data-date parameters on <li>s.
Muck around with passing forward the entry ID's as embed variables. This requires a total of 3 EE channel:entry tags plus an embed so it is definitely less efficient on the server side, if you are concerned about such things.
Incidentally, most of the EE questions are now handled in the EE SE. You might get a different/better answer over there.

Any way in Expression Engine to simulate Wordpress' shortcode functionality?

I'm relatively new to Expression Engine, and as I'm learning it I am seeing some stuff missing that WordPress has had for a while. A big one for me is shortcodes, since I will use these to allow CMS users to place more complex content in place with their other content.
I'm not seeing any real equivalent to this in EE, apart from a forthcoming plugin that's in private beta.
As an initial test I'm attempting to fake shortcodes by using delimited strings (e.g. #foo#) in the content field, then using a regex to pull those out and pass them to a function that can retrieve the content out of EE's database.
This brings me to a second question, which is that in looking at EE's API docs, there doesn't appear to be a simple means of retrieving the channel entries programmatically (thinking of something akin to WP's built-in get_posts function).
So my questions are:
a) Can this be done?
b) If so, is my method of approaching it reasonable? Or is there something stupidly obvious I'm missing in my approach?
To reiterate, my main objective here is to have some means of allowing people managing content to drop a code in place in their content that will be replaced with channel content.
Thanks for any advice or help you can give me.
Here's a simple example of the functionality you're looking for.
1) Start by installing Low Replace.
2) Create two Global Variables called gv_hello and gv_goodbye with the values "Hello" and "Goodbye" respectively.
3) Put this text into the body of an entry:
[say_hello]
Nice to see you.
[say_goodbye]
4) Put this into your template, wrapping the Low Replace tag around your body field.
{exp:low_replace
find="[say_hello]|[say_goodbye]"
replace="{gv_hello}|{gv_goodbye}"
multiple="yes"
}
{body}
{/exp:low_replace}
5) It should output this into your browser:
Hello
Nice to see you.
Goodbye
Obviously, this is a really simple example. You can put full blown HTML into your global variable. For example, we've used that to render a complex, interactive graphic that isn't editable but can be easily dropped into a page by any editor.
Unfortunately, due to parse order issues, EE tags won't work inside Global Variables. If you need EE tags in your short code output, you'll need to use Low Variables addon instead of Global Variables.
Continued from the comment:
Do you have examples of the kind of shortcodes you want to support/include? Because i have doubts if controlling the page-layout from a text-field or wysiwyg-field is the way to go.
If you want editors to be able to adjust layout or show/hide extra parts on the page, giving them access to some extra fields in the channel, is (imo) much more manageable and future-proof. For instance some selectfields, a relationship (or playa) field, or a matrix, to let them choose which parts to include/exclude on a page, or which entry from another channel to pull content from.
As said in the comment: i totally understand if you want to replace some #foo# tags with images or data from another field (see other answers: nsm-transplant, low_replace). But, giving an editor access to shortcodes and picking them out, is like writing a template-engine to generate ee-template code for the ee-template-engine.
Using some custom fields to let editors pick and choose parts to embed is, i think, much more manageable.
That being said, you could make a plugin to parse the shortcodes from a textareas content, and then program a lot, to fetch data from other modules you want to support. For channel entries you could build out of the channel data library by objectiveHTML. https://github.com/objectivehtml/Channel-Data
I hear you, I too miss shortcodes from WP -- though the reason they work so easily there is the ubiquity of the_content(). With the great flexibility of EE comes fewer blanket solutions.
I'd suggest looking at NSM Transplant. It should fit the bill for you.
There is also a plugin called Shortcode, which you can find here at
Devot-ee
A quote from the page:
Shortcode aims to allow for more dynamic use of content by authors and
editors, allowing for injection of reusable bits of content or even
whole pieces of functionality into any field in EE

If entry id then show certain content

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:

ExpressionEngine show channel content outside of loop

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.

Resources