Is there a cachebust variable in mkdocs templates? - caching

Is there anything like {{ time() }} or even more ideally {{ sha1sum('main.js') }} which I could use as a cachebust parameter in my theme templates?
Yes I'm aware of server side caching headers, but I don't have control of those.

The best I found so far is this {{ build_date_utc.strftime('%S%f') }} based on documentation I found here: http://www.mkdocs.org/user-guide/custom-themes/#template-variables
So now I can do this:
<script src="/static/js/main.js?cb={{ build_date_utc.strftime('%S%f') }}">
Which invalidates the cached file much more than it should, but at least it solves the problem.

Related

Laravel - Public_Path is Returned as Local System Path

I have an odd issue but I believe could be readily changed with a configuration I might not know about.
So if I want to access the path of an attachment I use the following code in my blade:
{{ $volunteer->photoID->attachment}}
Which returns me this:
public/volunteers/tgjW0GOQTzSEjG7F5Wlq0G9mEdGJ7fE7TLxpKRyn.jpg
But I am trying to put the image inside of a pdf, and because of the loading requirements, I am having to format the return in the blade as such:
{{ public_path($volunteer->photoID->attachment)}}
The problem is this returns:
E:\webserver\htdocs\hopin\public\public/volunteers/tgjW0GOQTzSEjG7F5Wlq0G9mEdGJ7fE7TLxpKRyn.jpg
Which isn't usable in the img element. So is there something I am doing wrong? Or is there a better way of creating the usable path?
Try using realpath when outputting the attachment:
{{ realpath(public_path($volunteer->photoID->attachment)) }}

Pass class object from ruby to liquid (via Jekyll)

UPDATE FOR CLARIFICATION.
I deleted the original question because it was confusing. Maybe this one is better?
I currently have something like this (simplified for brevity):
module Jekyll
module TOCGenerator
def toc(html)
...via nokogiri, get all <h3> tags, make table of contents entry
for each.
end
def contentWithTocAnchorLinks(html)
...make "back to top" anchor links under each <h3> tag that will
take the user back up to the table of contents
end
end
end
Then in the template:
<section>{{ content | toc }}</section>
<section>{{ content | contentWithTocAnchorLinks }} </section>
This works fine, but it seems sloppy. I've also tried stuffing both toc and contentWithAnchorLinks into an array and then doing something like {{ content | tocArray | first }} which also worked, but not very well (in some cases there is no table of contents and it was confusing). Anyway, what I would like to be able to do is something like this:
{% capture toc_content %}{{ content | toc_generate }}{% endcapture %}
<section> {{ toc_content.toc }} </section>
<section> {{ toc_content.content }}</section>
Jekyll does this all the time, as in {{ page.title }} but I'm not clear on how to replicate it. I only assume that a Ruby class is involved somewhere.
Does that make more sense?
If I understand your question, you want to parse a content, get some customers infos from it, and render a table of content.
From the Information Architecture point of view, you are supposed to store your customer datas in an atomic manner. For this, Jekyll offers you data files and collections that can be very helpful in your case.
If you need to make some basic transformations on your "objects" you can use liquid or jekyll filters.

Output Available Objects and Properties in Liquid Templates

Is there a way to output (for debugging/informational purposes) the available objects and object properties in a liquid template?
That is, say I'm using the jekyll site generation tool, and I'm in my index.html template (which is, to my understanding, a liquid template). It might look something like this
{% for post in site.posts %}
<li><span>{{ post.date | date_to_string }}</span> ยป {{ post.title }}</li>
{% endfor %}
Are there any template tags I could use that would tell me/output a variable named post was available in this template (as well as the other templates). Also, are there any template tags I could use that would tell me the post object has the keys date, title, url, excerpt, permalink, etc.
There's no way to do this from a Liquid template that I'm aware of. I used the following bit of Ruby code to do it in a test for Jekyll though (setup_post is a helper method in Jekyll's test suite)
post = setup_post("2008-11-21-complex.textile")
classes = []
Liquid::Template.parse(post.content).root.nodelist.each do |token|
classes << token.name if token.is_a?(Liquid::Variable)
end
It should be possible to write a Jekyll plugin that could output this stuff on your page based on the above code.

Laravel 4 Former::checkbox() always checked

I'm having an issue with the Laravel 4 Package Former and the use of checkboxes. I'm trying to Former::populate() a user edit form within a blade template but my checkboxes are always checked.
Here is my current code:
{{ Former::checkbox('is_admin')->text('Is Admin?'); }}
I've tried:
{{ Former::checkbox('is_admin')->text('Is Admin?')->check(false); }}
and
{{ Former::checkbox('is_admin')->text('Is Admin?')->forceValue(false); }}
To no avail.
My database field 'is_admin' is a boolean field. I thought maybe Former didn't like 1s and 0s but it doesn't uncheck my checkboxes even if I set a getter to return false.
Any Ideas?
Thanks
Sounds like a bug with Former.. Keep in mind it looks like you can overrule whatever happened with populate with populateField.

PyroCMS outputting profile custom fields

I have the following custom fields in my users profile. Something I've noticed is that these will output the currently logged in users fields. How do I get these fields to appear for the currently viewing user profile? I need to be able to see the selected user profiles data and not the logged in users data.
{{ user:your_address }}, {{ user:address_line3 }}, {{ user:state }}
You can pass a user id to the user plugin tags.
{{ user:your_address user_id="4" }}
Or us the profile tag if you have more than one tag.
{{ user:profile user_id="4" }}
{{ your_address }}
{{ address_line3 }}
{{ /user:profile }}
This is for PyroCMS version 2.1. If you have an older version you may need to update the user plugin.
From here: http://docs.pyrocms.com/2.1/manual/plugins/user
Edit
You can pass a variable to the user tags like so.
{{ user:your_address user_id="{{ user_id_var }}" }}
But you will need to set the id when you build your template in the controller, and pass the variable to the page somehow (via a URI segment?).
$this->template->user_id_var = $this->uri->segment(2);

Resources