ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

How do you truly use DRY principals in EE - e.g. sharing the same custom field across multiple template groups?

May 11, 2011 6:49pm

Subscribe [5]
  • #1 / May 11, 2011 6:49pm

    cmscss

    144 posts

    Hi There,

    We have ‘excerpt_text’ and ‘excerpt_image’ fields which along with the page title, are used when listing pages/posts, as META descriptions and as the excerpt when sharing pages or posting to Facebook.

    These fields need to be shared across multiple template groups and placed in a single website header which is then shared across the entire site.

    But this doesn’t seem possible - is this correct?

    What is the official way of handling this?

    And can you assign the same custom field to multiple template and channels without having to use the publish layouts feature which seemed to require constant resetting when we used one template group on this site last year - we ended up rebuilding it.

    Cheers

    Ben

  • #2 / May 12, 2011 10:52am

    Kevin Smith

    4784 posts

    Hi There,

    We have ‘excerpt_text’ and ‘excerpt_image’ fields which along with the page title, are used when listing pages/posts, as META descriptions and as the excerpt when sharing pages or posting to Facebook.

    These fields need to be shared across multiple template groups and placed in a single website header which is then shared across the entire site.

    But this doesn’t seem possible - is this correct?

    What is the official way of handling this?

    Hi Ben—

    There’s not necessarily an official way to handle these things in EE, but here are some best practices. It sounds like for page title, META descriptions, etc., something like User Defined Global Variables is what you need. Have you given those a try?

    As for the custom fields, I’m assuming those are used in a channel with multiple entries and so the value of those fields will change depending on which page is being displayed, correct? I may be missing something here, but what’s to stop you from just using the ordinary Channel Entries tag to display those? If you want to display fields from a channel entry that isn’t being dynamically called based on the URL, make sure you use dynamic=“no” and entry_id=“147” in the channel entries tag to explicitly declare the entry you want to display.

    And can you assign the same custom field to multiple template and channels without having to use the publish layouts feature which seemed to require constant resetting when we used one template group on this site last year - we ended up rebuilding it.

    You can assign the same custom field group to two different channels, but only as groups. If you want to assign a single custom field to two channels, that custom field would need to be part of each custom field group that is assigned to those channels. Does that make sense?

    Hope this helps!

    Kevin

  • #3 / May 15, 2011 9:10pm

    cmscss

    144 posts

    Thanks for the reply Kevin,

    I’m not that experienced with EE (about a year) so I have a few questions on the methods you describe:

    something like User Defined Global Variables is what you need. Have you given those a try?

    Can User Defined Global Variables appear in the entry page so that the client can edit those as part of a post/page?

    I may be missing something here, but what’s to stop you from just using the ordinary Channel Entries tag to display those?

    I don’t fully understand but if I did it that way, I think I’d need to create a bunch of conditionals to test for the different intro text and image fields and if one contained content, display it.

    Would that be a good way to do it?

    BTW, when using conditionals, do they get cached by default or do you have to configure things for more efficient caching?


    Overall though, I guess I don’t understand why you can’t create a field, then use it in any template/channel you’d like - seems like a more efficient way of doing things OMHO.

    Cheers mate, look forward to your reply.

    Ben

  • #4 / May 16, 2011 9:18am

    Sue Crocker

    26054 posts

    Hi, Ben.

    User defined global variables aren’t displayed with your channel entry fields.

    If you need this kind of granularity outside of what EE supports natively is to use:

    http://ee-garage.com/nsm-better-meta

    As far as caching goes, you might want to look at this page in the docs: EEDocs:// Data Caching and Performance

  • #5 / May 16, 2011 2:58pm

    narration

    773 posts

    Here’s an add-in which should handle part of what you want: http://devot-ee.com/add-ons/seolite/.

  • #6 / May 16, 2011 5:03pm

    Sue Crocker

    26054 posts

    Thanks for the additional link, Clive. I knew I forgot one. 😊

    cmscss - how do those potential add-ons sound to you?

  • #7 / May 31, 2011 3:12pm

    EmilyLimeRed

    44 posts

    Overall though, I guess I don’t understand why you can’t create a field, then use it in any template/channel you’d like - seems like a more efficient way of doing things OMHO.

    I have to agree here.  I was just wondering the same thing.. I have a few different channels for a site I’m working on (one is for general content pages, one is for the staff, one is for research, another for articles, &c.), but each of the corresponding pages will have different “headline images”.. why is it there’s not a way to use the same field (or at least the same field name) across multiple channels?  instead I have to keep making new headline image fields.. “staff_headline_image” “research_headline_image” and to make it even more difficult, I then have to call a different field name in every template too..

    it certainly seems like it would make more sense to allow a single field to exist in multiple channels, or at least allow the field name to be the same to save some time templating..

    is there something I’m missing here?  IS there an easier way?

  • #8 / May 31, 2011 3:52pm

    Brandon Jones

    5500 posts

    EmilyLimeRed,

    There was an add-on like this for EE 1.x but it doesn’t look like it’s been ported to 2.x yet. Nevertheless, more field flexibility is something that’s on our radar, so we appreicate the feedback!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases