PyroCMS outputting profile custom fields - pyrocms

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);

Related

I'm using Laravel with Laratrust, How to print a role that's attached to an account? [duplicate]

This question already has answers here:
Retrive Roles name for collection of users in laravel
(2 answers)
Closed 1 year ago.
In my home page, I can print the name and email of a logged account using:
{{ Auth::user()->name }}
{{ Auth::user()->email }}
but when i want to print the role that attached to the account using this:
{{ Auth::user()->roles }}
it prints a collection of keys and values of all the data in the table instead, like this:
[{"id":3,"name":"mahasiswa","display_name":"Mahasiswa","description":"Mahasiswa","created_at":"2021-03-22T13:09:14.000000Z","updated_at":"2021-03-22T13:09:14.000000Z","pivot":{"user_id":4,"role_id":3,"user_type":"App\\Models\\User"}}]
I just want to extract the name or display_name.
So, i'm using {{ Auth::user()->roles->where('name')->first() }} but it still shows the same collection but without the "[]" brackets.
Thanks for the answers guys! I appreciated it.
But I just found the answer here https://stackoverflow.com/a/39357511/15471776
So, I changed my code to {{ Auth::user()->roles->first()->display_name }} and it displays the role name that attached to my logged account perfectly.
You should get first record then get field.
{{ Auth::user()->roles->first()->get('name') }}
Here is reference from docs
https://laravel.com/docs/8.x/collections#method-get

Is there a cachebust variable in mkdocs templates?

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.

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 - Show Blog Posts with date in future

in my PyroCMS website I want to display rock shows of a rock band that will occur in the future. I use a conditional to check whether the date of the blog post (which contains the rock show information) occurs in the future or not. But apparently PyroCMS does not show any blog post that has a date in the future. How can I solve this?
Below the code that I use:
<h2>Upcoming shows</h2>
{{ blog:posts category="shows" order-by="created_on" order-dir="asc" }}
{{ if created_on >= time() }}
<div class="upcoming_show_info">{{title}}</div>
{{ endif }}
{{ /blog:posts }}
Thanks!
If you just need a dirty fix you have to edit posts() function in system/cms/modules/blog/plugin.php. In version 2.1 you can find it on line 51.
...
->where('created_on <=', now())
...
Becomes:
...
->where('created_on >=', now())
...
This way you can also remove that created_on check in your view file as the plugin is going to return only future dated posts. (If you need both "past" and "future" posts, simply delete that line)
Although this is a quite easy way to fix your problem, it will be better if you create a new function inside plugin.php file and use that in your views.

Resources