Take the 2-minute tour ×
ExpressionEngine® Answers is a question and answer site for administrators, end users, developers and designers for ExpressionEngine® CMS. It's 100% free, no registration required.

I am a Drupal developer doing my fist ExpressionEngine project.

Drupal uses a model of content 'blocks' that can be placed in regions on pages based on certain rules.

I understand the use of channels but can I tailor this to ExpressionEngine? Do I just create multiple channels and how can I make these blocks more flexible so I can choose which pages they appear on.

share|improve this question
    
If I had understood the concept of blocks, I could try to help you. Can you give us more details? –  Robson Sobral Jan 31 at 11:36
1  
Channel is place where we keep entryes data (main place). Snippets with tags inside possible is more close to blocks concepts. For some project it is can be Low Variables. For some - Content Elements. But you need to start from fundamental knowlage. I don't think that is short way to learn EE by comparing with drupal methods. –  Max Lazar Jan 31 at 11:48
    
I create a small bit of text "about us" it has a few lines. I want that block to apear on the homepage and in the sidebar of 2 more pages. In drupal I can create a list of url aliases of the pages I want the blocks on /aboutus, /contactus. If I change the block content it changes on every page. –  Roscoeh Jan 31 at 11:52

1 Answer 1

up vote 4 down vote accepted

Welcome to ExpressionEngine! The first thing to understand is that EE has no concept of "regions" - it completely separates your content from your templates. The only content which appears at any given URL (which essentially is the same as your templates - templates in EE are like routes or controllers) is what you explicitly define inside your templates.

So, having said that, there are a few ways you could accomplish what you're after.

Use a channel

You could setup a channel, and you could even call it "Blocks". You could then give it as many fields as you like - content, maybe an image, whatever might be useful for you for each "block".

Then, in your EE template - presumably inside of a snippet or an embedded template, which you'd be using throughout other templates - you'd write some conditional code:

{if segment_1 == 'about-us'}
    {exp:channel:entries channel="block" entry_id="32" disable="member_data|pagination|categories"}
        <div class="block about-us-block">
            <h3>{title}</h3>
            {block_content}
        </div>
    {/exp:channel:entries}
{/if}

(This assumes that the entry_id of the "About Us" block was 32.)

The problem with this approach is that if you have a number of blocks on your page (in a sidebar or whatever), this is very resource intensive (running a channel:entries tag several times).

Global Variables

This approach also lets you manage your "block" content inside of the control panel, but depending on how you approach it, gives you less flexibility. Global variables are always loaded, so you can use them anywhere in your templates with no performance hit.

If you use EE's global variables, you are limited somewhat, as each is just an empty text area where you dump text and/or HTML. But if you upgrade to something like Low Variables, you can create variables much like you create custom channel fields, and get much more sophisticated.

So if you dumped the entire HTML contents of your block inside of a global variable called gv_about_us_block, you could do:

{if segment_1 == 'about-us'}
    {gv_about_us_block}
{/if}

Or if you broke your block up into parts (say, inside of a Low Variables group):

{if segment_1 == 'about-us'}
    <div class="block about-us-block">
        <h3>{lv_about_us_block_title}</h3>
        {lv_about_us_block_content}
    </div>
{/if}

Snippets

Snippets are a more advanced form of global variables, in that they can contain EE module/plugin tags as well. They are also managed inside the control panel (though many use add-ons such as Snippet Sync to store them in the filesystem instead). You could actually replicate or combine the above two approaches with snippets if you wanted - use a channel entry and put all that code in a snippet (which you then call inside your template conditional), or just dump your entire "block" content into a snippet and use it exactly as you would the first example above under Global Variables.

Add-ons

There is an add-on called Widgets, which I have no experience with, and which appears not to have had too much development activity as of late, but may well work for you and get the job done. Its concept is similar to WordPress' widgets (but of course, since EE is a blank slate with no predefined regions of any sort, the widgets need to be added to your templates manually).

Hope that gives you some ideas on how to approach this!

share|improve this answer
1  
great answer thanks, I think what you loose in somethings you gain in another, although the block system is really flexible in drupal, the over-bloated, messy html is not something I am going to miss. –  Roscoeh Jan 31 at 14:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.