webhook / webhook-cms

The CMS layer for Webhook.com
http://www.webhook.com
MIT License
178 stars 41 forks source link

url() template helper produces inconsistent results #169

Closed narkeeso closed 10 years ago

narkeeso commented 10 years ago

I've stumbled upon some issues regarding the url() template helper. I was working on the navigation and was attempting to remove hardcoded urls for content types. However, url() was giving me inconsistent results depending on a few different factors.

Factors:

All results are assumed that the user has not changed the url/slug.

Single Content Type with 'About' as Title

{{ url('about') }}
# returns nothing

{{ url(cms.about) }}
# returns /about/

Single Content Type with 'Selected Projects' as Title

{{ url('selectedprojects') }}
# returns nothing

{{ url(cms.selectedprojects) }}
# returns /selected-projects/, expected result is /selectedprojects

Multiple Content Type with 'Team' as Title

{{ url('team') }}
# returns /team/

{{ url(cms.team) }}
# returns //

Multiple Content Type with 'The Team' as Title

{{ url('theteam') }}
# returns nothing

{{ url(cms.theteam) }}
# returns //
LtSquigs commented 10 years ago

The types are available on cms_types.type not cms.type.

cms.type refers to the data not to the type itself.

So in order: 1) Is working as expected. The type for a one-off does not have a slug so url('type') will not return a url, but the one off object does so url(cms.type) works.

2) Same as one. As for it being an unexpected url, the default slug behavior is to convert spaces in type names to dashes, as per normal url conventions, the slug is not the same as the type names variable name. If you've explicitly changed the slug through the custom slug options and are still getting an unexpected slug this would be a problem.

3) Working as expected. url('teams') retrieves the teams type and outputs the slug, url(cms.teams) is trying to get the url of the teams data. You would want url(cms_types.teams)

4) Same as 3

narkeeso commented 10 years ago

@LtSquigs

Thanks for looking at this. This could very well be that I am not using the url() helper as intended. If this is the case I think the documentation should be clarified on these topics. It looks like it's main function is to help retrieve slugs for content data. However, on pages/index.html an example is used with the url() helper:

 <ul>
  {% for type in cms_types %}
    <li><a href="{{ url(type) }}">{{ type.name }}</a></li>
  {% endfor %}
</ul>

Simple enough, it looks like I can retrieve content type urls. The only issue is that cms_types only seems to return multi content type. I currently have 4 content types and only 2 of them are shown in this loop. 2 of them are single and the other 2 are multi.

From a user experience perspective, my suggestion would be to make content types have similar properties or behave similarly.

1) Is working as expected. The type for a one-off does not have a slug so url('type') will not return a url, but the one off object does so url(cms.type) works.

Why can't a one-off type just contain a slug/url? I do think url() needs better documentation or clarification or content types need better clarification on how they behave and interact with helpers.

2) Same as one. As for it being an unexpected url, the default slug behavior is to convert spaces in type names to dashes, as per normal url conventions, the slug is not the same as the type names variable name. If you've explicitly changed the slug through the custom slug options and are still getting an unexpected slug this would be a problem.

Is the url() helper a sluggify helper or a helper to retrieve the url() from the cms? If it's to retrieve the url() from the cms data then this is not working to me as expected. The content type, 'Selected Projects' when created, creates a url of /selectedprojects/ not /selected-projects/. I also tried changing the slug on the one-off content type to /selectedprojects/ and it was still being returned as /selected-projects/.

3) Working as expected. url('teams') retrieves the teams type and outputs the slug, url(cms.teams) is trying to get the url of the teams data. You would want url(cms_types.teams)

Please compare result of Multiple Content Type with 'Team' as Title and Multiple Content Type with 'The Team' as Title - since I do not think this is working as expected. The string example with no spaces in title returns /team/ which is expected. However, the string example with spaces in the title 'The Team' returns nothing for url('theteam')

LtSquigs commented 10 years ago

Returning only multiple content types and not one-offs is intentional. This is because one-offs are used from everything from saving extra settings to creating new pages, so often having them show up in the type list is undesirable (if you have a header with links to all your list pages, you wouldnt want a one-off link showing up for a one-off thats used for twitter settings for example). We should be more explicit in the docs about this.

1) Ill make it so the one off type includes the slug, makes sense to be there

2) The 'urls' in the CMS are not related to the urls that are generated by the generator. The names generated in the CMS (selectedprojects in this case) are just identifiers that are used to reference them in templates. These are more restrictive than a URL has to be because they also double as variable names. The URLs on the generator side either default to a slugified version of the name (using a common slug library) or to the Custom URL that is defined on the type through the CMS.

3) I'll have to look into your firebase to see why this isnt working, may be that the data is being saved in a weird way.

narkeeso commented 10 years ago

Thanks for clarifying and thanks for listening. I agree that one-offs in cms_types are often undesirable when used for navigation. Let me know what you need if you want to look at my firebase data. I'll park myself in #webhook

LtSquigs commented 10 years ago

Ok these issues have been fixed, the space was because the check was against name not id, and one offs are now retrievable by url('id')

narkeeso commented 10 years ago

:+1: Thank you!