librelist archives

« back to archive

Content "Partials"

Content "Partials"

From:
Stefan Goodchild
Date:
2011-07-08 @ 10:57
Hi All,

Wondered if there was an existing easy way to render out a specific bit of
content somewhere else in the site? For example I have several places 
where a paragraph of descriptive text appears and would rather have a 
single "shared" folder with a markdown file in it that I could include in 
a similar way to the layout.haml includes the footer.haml.

I know I could probably just stick in as a haml partial in the views 
folder and include it that way but I would rather have the content editors
only have access to the content directory :-)

Rgds, Stefan

Re: [nesta] Content "Partials"

From:
Graham Ashton
Date:
2011-07-08 @ 11:07
On 8 Jul 2011, at 11:57, Stefan Goodchild wrote:

> I know I could probably just stick in as a haml partial in the views 
folder and include it that way but I would rather have the content editors
only have access to the content directory :-)

That's what I was about to suggest (and is what I do). I agree it could be
quite useful.

Can you give me a concrete example? I'm trying to weigh up whether the 
content author needs to be able to insert these snippets at any point in a
page (in which case they'll have to reference them inline while writing a 
.mdown or .textile file, which is a bit icky from an implementation 
perspective) or whether they just need to write snippets that could then 
be inserted within a template.

The latter option could look like this...

The author edits text in here:

  content/pages/snippets/re-usable-thing.mdown

Whoever is writing the HTML/CSS could then render the contents in the 
relevant location in the template. Something like this, maybe (the first 
two lines are from the default theme's page.haml template):

    %article(role="main")
      ~ @page.to_html(self)

    %section.other
      = snippet("re-usable-thing")

Writing the snippet helper method would be pretty straightforward.

If authors really do need to insert re-usable chunks of text within the 
copy of their pages then this obviously wouldn't cover it.

Re: [nesta] Content "Partials"

From:
Stefan Goodchild
Date:
2011-07-08 @ 11:23
On 8 Jul 2011, at 12:07, Graham Ashton wrote:

> On 8 Jul 2011, at 11:57, Stefan Goodchild wrote:
> 
>> I know I could probably just stick in as a haml partial in the views 
folder and include it that way but I would rather have the content editors
only have access to the content directory :-)
> 
> That's what I was about to suggest (and is what I do). I agree it could 
be quite useful.
> 
> Can you give me a concrete example? I'm trying to weigh up whether the 
content author needs to be able to insert these snippets at any point in a
page (in which case they'll have to reference them inline while writing a 
.mdown or .textile file, which is a bit icky from an implementation 
perspective) or whether they just need to write snippets that could then 
be inserted within a template.

I have used the helper stuff you wrote for me to include a list of 
different sections of my portfolio on the front page of my site and each 
section has a bit of blurb. That blurb about the two things I do is 
repeated on the portfolio page and on each of the sub category pages. This
means the same bit of copy is in three places.

If you take a look in my repo (you should still have access) you'll see 
what I'm on about and it's up on heroku as well -> 
http://furious-robot-355.heroku.com/

> Whoever is writing the HTML/CSS could then render the contents in the 
relevant location in the template. Something like this, maybe (the first 
two lines are from the default theme's page.haml template):
> 
>    %article(role="main")
>      ~ @page.to_html(self)
> 
>    %section.other
>      = snippet("re-usable-thing")

This is the kind of thing I was thinking of. I'm already using haml in the
content folder so this would work really well for me.

Rgds, Stefan