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

RFE: Make it possible to include content files from other content files #1902

Closed
atodorov opened this issue Jan 25, 2016 · 8 comments
Closed
Assignees

Comments

@atodorov
Copy link
Contributor

Hi guys,
I have several pages which have the same boiler plate text. It's a warning/disclaimer notice which gets included where necessary. As far as I can see it is not possible to do this inside my content files.
For example instead of linking to another file with [disclaimer]({filename}disclaimer.md] I want to be able to write {include}disclaimer.md and the text will be automatically included in the current page being processed.

Please let me know if this exists (or partially exists). I intend to work on this feature b/c I need it.

atodorov added a commit to MrSenko/pelican that referenced this issue Feb 11, 2016
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
atodorov added a commit to MrSenko/pelican that referenced this issue Feb 11, 2016
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
@yulongbai
Copy link

hello? Is this syntax can only be used in markdown files? or any kind of textfiles, like .rst or plain .txt, in the content folder?
I have noticed that this is specially useful for organizing large posts.

@atodorov
Copy link
Contributor Author

I've used a .html file to test it. As far as I can tell the curly braces syntax (also {filename}, {category}) can be used in any kind of text file. I still need to hear code review from the project maintainers though.

@atodorov
Copy link
Contributor Author

@mitchtbaum - I've received a notification about you commenting on this issue but the comment got lost somehow.

@naturallymitchell
Copy link
Contributor

@atodorov: Sorry about that. I had started to comment, and somehow this form submitted before finishing it, so I wrote another one saying that happened and deleted both. #tangled-web-problems

I looked further into this, and aside from Pelican's current link syntax and potential additions and improvements which we can address in another issue, I believe I have already produced a good solution for your use case. I need to fix upstream dependencies so I can make stable links to it (here and in Pelican's plugin meta-repo) and finish documentation, so I am working on that now. // Temporarily, you can find usable, pre-released code in https://github.com/mitchtbaum?tab=repositories //

In a nutshell, you would create a 'notice' (article with that category) for each one you want to use, and you would reference your desired notice from any article with a notice: warning or notice: whatever metadata entry, and then in your article template or specific category template, you would include something like this chunk:

{% if article.notice %}
  {% for reference in article.notice %}
    <div id="notice">
      <b>Notice:</b> {{ reference.body }}
    </div>
  {% endfor %}
{% endif %}

How would that work for you?


Aside: You can see a small writeup before I had worked out this reference plugin's full design in #1169. I will mark that as complete when I get this code into a repo where we can continue to work on it, #1488.

Note: edited Jinja example to add div wrapper and changed styling to wrap only leading text saying what it is.

@atodorov
Copy link
Contributor Author

How would that work for you?

It won't as far as I can understand. Correct me if I'm wrong but your solution requires me to have a template in which to reference the text I need to include, right ?

What I want to do is include text inside my content files (e.g. html pages or markdown posts). I don't want to mess about with templates.

@naturallymitchell
Copy link
Contributor

References take place only in content. They are simple key-value pairs going from one piece of content to another using metadata.

So for instance, /content/notice/bring-water.md could have body text "Bring a water bottle!", and /content/travel/kalahari.md could have title: Kalahari Desert, notice: bring-water, and body text like "It gets dry there, like any desert."

When your content (markdown, etc) gets rendered into a desired output (html, etc), it will go wherever you put it and have whatever style you give it, as per your theme.

imho, data feels most comfortable (so to speak) when it is kept separate from any logic about where to put it and how it could look.

atodorov added a commit to MrSenko/pelican that referenced this issue Mar 11, 2016
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
atodorov added a commit to MrSenko/pelican that referenced this issue Mar 11, 2016
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
atodorov added a commit to MrSenko/pelican that referenced this issue Mar 11, 2016
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
atodorov added a commit to MrSenko/pelican that referenced this issue Mar 12, 2016
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
atodorov added a commit to MrSenko/pelican that referenced this issue May 26, 2016
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
@leotrs
Copy link

leotrs commented Aug 14, 2016

@atodorov

I have several pages which have the same boiler plate text. It's a warning/disclaimer notice which gets included where necessary

I wrote the jinja2content plugin for this purpose. You can see it in action here. The file includes several others by using a jinja2 {% include %} statement.

The plugin also provides full jinja2 functionality (before the theme's templates are rendered, so the content that is passed onto the plugin does not have the includes any more).

cc. @mitchtbaum

@justinmayer
Copy link
Member

PR #1909 was submitted to address this and is currently awaiting review from @getpelican/reviewers.

atodorov added a commit to MrSenko/pelican that referenced this issue Dec 14, 2016
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
atodorov added a commit to MrSenko/pelican that referenced this issue Dec 14, 2016
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
atodorov added a commit to MrSenko/pelican that referenced this issue May 31, 2017
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
atodorov added a commit to MrSenko/pelican that referenced this issue Jun 10, 2017
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
@justinmayer justinmayer self-assigned this Jul 23, 2019
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 1, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 1, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 1, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 1, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 1, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 1, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 2, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 2, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 2, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 2, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 2, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 2, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 2, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 2, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 3, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 4, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 4, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 4, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 4, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 4, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 4, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 4, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 4, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 4, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 4, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 4, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 4, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 4, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 6, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 6, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C pushed a commit to Lucas-C/pelican that referenced this issue Oct 6, 2019
The new {include} syntax makes it possible to include
frequently used text snippets into your content.
Lucas-C added a commit to Lucas-C/pelican that referenced this issue Oct 17, 2019
justinmayer added a commit that referenced this issue Oct 17, 2019
Add docs on how to include other files - fix #1902
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants