Skip to content

Commit

Permalink
add {{ content_dir }} and {{ content_url }} to twig_vars
Browse files Browse the repository at this point in the history
This allows you to use {{ content_dir }} or {{ content_url }} in your theme templates.

I use it for adding images (sliders, header images, logos) or other file-specific content that I still want to be accessible by the client. It is a lot easier for them if their site "lives" in the content folder.

My usage: 

```html
{% for slide in config.slides %}
  <div>
    <img src="{{ content_url }}/images/{{ slide }}">
  </div>
{% endfor %}
```

Output

```html
<div>
  <img src="http://ohdoylerules.com/images/slide-1.jpg">
</div>
<div>
  <img src="http://ohdoylerules.com/images/slide-2.jpg">
</div>
```

This makes for a universal image. Which can be used regardless of the theme I have enabled.
  • Loading branch information
james2doyle committed Apr 11, 2014
1 parent 2bbbcce commit d03ef97
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/Phile/Template/Twig.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public function render() {
'base_url' => $this->settings['base_url'],
'theme_dir' => THEMES_DIR . $this->settings['theme'],
'theme_url' => $this->settings['base_url'] .'/'. basename(THEMES_DIR) .'/'. $this->settings['theme'],
'content_dir' => CONTENT_DIR,
'content_url' => $this->settings['base_url'] .'/'. basename(CONTENT_DIR),
'site_title' => $this->settings['site_title'],
'current_page' => $this->page,
'meta' => $this->page->getMeta(),
Expand Down

0 comments on commit d03ef97

Please sign in to comment.