Short Question: I'm coming from ExpressionEngine where 'dynamic' would do the trick. However I can't seem to figure out how to do this in Craft.
I want to be able to use one Channel to show content in different places on the site. Can Craft look at a particular URL segment and load the entry?
Longer explanation I have many users who will have their own 'site' on a website. Each 'site' will have four basic pages -welcome -my story -my work -blog
The Blog page will show entries authored by them, but all users will share the same channel.
I have it all working for the main pages. I'm creating a Structure section for each user. I point it to a template (_userTemplates/johnDoe) that contains some variables and includes:
{% extends "_layout" %}
{% set author = "12" %}
{% set sectionName = "johnDoe" %}
{% set content %}
{% include "_partials/content" %}
{% endset %}
Layout looks like this:
<!DOCTYPE html>
<html>
{% include "_partials/htmlHead" %}
<body>
{% include "_partials/nav" %}
{{ content }}
{% include "_partials/footer" %}
</body>
</html>
_partials/nav has dynamic navigation. It pulls the variable "sectionName" from the user's template to show their navigation links for their structure pages.
<nav class="desktop {{ type is defined ? type }}" role="navigation">
<div>
<ul>
{% set pages = craft.entries.section(sectionName) %}
{% nav page in pages %}
<li>{{ page.getLink() }}</li>
{% endnav %}
</ul>
</div>
</nav>
_partials/content looks like this:
{% if craft.request.getSegment(3) != '' %}
<section>
<div class="grid padded full-768">
{% include "_partials/contentBuilder" %}
</div>
</section>
{% elseif craft.request.getSegment(2) == 'blog' %}
<section>
<div class="grid padded full-768">
{% include "_partials/blogListing" %}
</div>
</section>
{% elseif craft.request.getSegment(3) == '' %}
<section>
<div class="grid padded full-768">
{% include "_partials/contentBuilder" %}
</div>
</section>
{% endif %}
The template that contains all the content, _partials/contentBuilder, looks like this:
<header>
<h1 class="alpha highlighted">{{ entry.title }}</h1>
</header>
{% for content in entry.contentEditor %}
{% if content.type == 'heading' %}
<h2>{{ content.heading }}</h2>
{% elseif content.type == 'subheading' %}
<h3>{{ content.subheading }}</h3>
{% elseif content.type == 'image' %}
{% for image in content.imageFile %}
<img src="{{ image.url }}"/>
{% endfor %}
{% elseif content.type == 'text' %}
{{ content.text }}
{% elseif content.type == 'blockquote' %}
<blockquote>{{ content.blockquoteQuote }}</blockquote>
{% if content.blockquoteCitation %}
<cite>{{ content.blockquoteCitation }}</cite>
{% endif %}
{% elseif content.type == 'video' %}
{% if content.videoTitle != '' %}
<h3>{{ content.videoTitle }}</h3>
{% endif %}
{{ craft.embedder.embed (content.videoUrl) }}
{% endif %}
{% endfor %}
</article>
This works great for the main Structure pages. However when the template route "johndoe/blog/{slug} points to _userTemplates/johnDoe this does not work. I get "Variable "entry" does not exist". I thought that the template route would look for an entry and then know which entry it is? I will try pulling the entry from the URL segment per one of the answers and see how that works. However I thought the route would work.
EDIT - Got it working using this in _partials/content:
{% if craft.request.getSegment(3) != '' %}
<section>
<div >
{% for entry in craft.entries.slug(slug).find() %}
{% include "_partials/contentBuilder" %}
{% endfor %}
</div>
</section>
{% elseif craft.request.getSegment(2) == 'updates' %}
<section>
<div>
{% include "_partials/updateListing" %}
</div>
</section>
{% elseif craft.request.getSegment(3) == '' %}
<section>
<div>
{% include "_partials/contentBuilder" %}
</div>
</section>
{% endif %}
It looks like I was expecting too much from the template route.
The goal of all this is to be able to give people their own "site", and do it quickly with code that is easy to manage and maintain. This method only requires a new section be created, set up the user with proper permissions, create their template partial, and set up the route. If there is a better way to do this, let me know.