Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

snippet templatetag not usable outside django-cms #491

Closed
deutrino opened this issue Jun 13, 2010 · 5 comments
Closed

snippet templatetag not usable outside django-cms #491

deutrino opened this issue Jun 13, 2010 · 5 comments

Comments

@deutrino
Copy link

Hello,

I'm developing a site with a mixture of django-cms and non-django-cms pages. The snippets plugin would be quite useful for sharing snippets between these, except there seems to be no template tag that I can import in order to use it easily in a non-django-cms template. It would be very nice if this were easy (or possible) to do.

@ojii
Copy link
Contributor

ojii commented Nov 4, 2010

this is possible now!

@vanschelven
Copy link

ojii, would you care to elaborate on how this is possible? I can't find any such tag...

@bradbeattie
Copy link

"this is possible now!"

Please elaborate. The plugins/snippet code doesn't seem to have any template tags.

@Lacrymology
Copy link

well, make it! it should be easy enough, as long as you have a way of identifying snippets

@bradbeattie
Copy link

As a quick proof of concept:

from cms.plugins.snippet.models import Snippet
from cms.plugins.snippet.cms_plugins import SnippetPlugin
from django import template

register = template.Library()

@register.simple_tag
def show_snippet(name):
    try:
        return SnippetPlugin().render(
            {},
            type('obj', (object,), {'snippet' : Snippet.objects.get(name = name)}),
            None
        )['content']
    except Snippet.DoesNotExist:
        return ""

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants