pyrocms files plugin variables - pyrocms

I want to pull a url segment variable into the pyrocms file plugin call. it would look like
{{files:listing folder="[segment(2)]"}}
or something of the sort. What is the trick for embedding
{{url:segments..}}
inside
{{files:listing folder="…}}
I am trying to setup this up for a conditional query for a photo gallery

If you take a look at the PyroCMS Tags documentation you will see this clearly documented in the "Tag Attributes" section.
You may also use the output from other tags as attribute values in your tags. For example if you wanted the url segment to default to the slug of the currently viewed page you could do this:
{{ url:segments segment="1" default=page:slug }}
Here is an example showing the proper use of quotes and braces when the tag used as the attribute value has an attribute itself.
{{ url:segments segment="1" default={foo:bar value="baz"} }}
Tip: Omit quotes and braces when using tags as attribute values. The only exception is when the tag you are using as the attribute value has its own attributes.
So you can do that easily with:
{{ files:listing folder={url:segments segment="2"} }}
Basically you don't need to pretend it's a string if it's not. You can just send the foo:bar arguments through, but it if has attributes you can "group" the attributes with the call via a single { and }.
Simple right? :)

Related

What's the easiest way to define a custom HTML-stringification?

Is there a way for me to define that when I just output a value in Go html templates the way the formatting is done instead of it printing a string representation without having to call a function to explicitcly convert it?
For example, let's say I have a type Person and I have a template with just {{.}} I want it to automatically create a link to that person's page but if I use the same template and passed a value of a different type some other HTML will be generated.
What I don't want to do is having to write something like {{.HTML}} or {{. | html}}. I'm already aware that these are possible but my question is specifically about how to avoid those.
I've played around with the thought of Person.String() having return the HTML code somehow without it being escaped but besides not getting that to work it also seems like an ugly solution.
Another solution I've thought about is to just pass everything as HTML into the template but then I couldn't access the attributes anymore (like {{.name}} to output just the name) and I'd also have to convert everything into HTML just in case it's used in the template.
Create a method that returns an template.HTML type. i.e.:
func (p *Person) HTML() template.HTML {
return fmt.Sprintf(`%s`, p.id, template.HTMLEscapeString(p.name))
}
Then in your template:
{{ .HTML }}

Show Dynamic image data to the img html element - Laravel, Collective

I am dealing with 2 variables here. 1st being $xyz which contains all the values I would like to bind to the form and 2nd being $fields which contains all the input fields.
I am looping through $fields->field_name to show all the form fields from the database.
But 1 of the fields being an image, which is a different case. I am simply trying to bind manually the image url to the img element here.
To successfully bind an image. I need 2 things, 1 being the field name which I can get it from $fields->field_name and second is the url which is in $xyz.
so, I plan to do something like: $xyz->get($fields->field_name). This means, I try to access $xyz object and get dynamic image field name. but not sure why my below code throws error:
<img src=" {{ url($xyz->get($fields->field_name)) }}" />
code like above works completely fine in Controller, not sure how to achieve this in Blade front-end Views.
error:
Type error: Argument 1 passed to Illuminate\Database\Grammar::columnize() must be of the type array, string given
I found the solution by myself:
below works, instead of using get:
{{ $xyz[$fields->field_name] }}

Laravel: variable as form value

First Laravel Project.
I want to make an "edit screen" where the "old values" are the predefined default value of the form input field.
I tried this:{{ Form::text('brand', '$product[0]->brand') }}
But I got back
$product[0]->brand
Instead of
Test brand
What I did wrong? What's the good syntax?
Usually, Laravel should reuse the last entry the user used if the form isn't validated as you can read here :
Also, please note that the value will first come from Flash Session Input, only secondly will the value argument be used. This means if your previous request was this form it will automatically display the value the user last entered.
But, if you want, can't you use something like
{{ Form::text('brand', $product[0]->brand) }}
Because you were saying you wanted that specific string by putting ' around your variable.
please use it:
{{Form::text('brand',null,array('class'=>'form-control'))}

Laravel, get the url for a controller/action from within the view

In my view I do not want to hardcode a url in just incase I change it... Is there a way to generate the hyperlink url by saying i'm going to use this controller and this action... something like:
<a href = 'echo ActionLink("Logout", "Authentication");'>Logout</a>
I also just found this...
Logout
What you need to do is to be able to refer to your routes somehow. There are two primary methods of doing this: naming them and referring to a controller action (i.e. Controller#action).
The best and most flexible, however, is to name your routes. This means that if you refactor your controllers (e.g. change the classnames or namespaces), you have to change less code (just where the route points to, rather than where each view reference is).
Whichever way you do it, you can use all sorts of helpers to get what you want. The following are all equivalent:
{{ link_to_route('route.name', 'Title) }}
{{ HTML::linkRoute('route.name', 'Title') }}
Title
Title
Similarly, you can use 'action' in place of 'route' in those helpers to do the equivalent version using the Controller#action way of specifying the route.

Printing repeated Django form fields individually

I have a Django forms dilemma. When rendering a form in a template, I usually prefer to print the form fields individually, in stead of using the form.as_p annotation. However, in the form I am working on I have a set of fields that are repeated an unknown number of times. For example, if there are 3 items being edited the fields would be:
field_name_1
field_email_1
field_name_2
field_email_2
field_name_3
field_email_3
But the number of items in not known to me beforehand. To solve this I am creating the fields in a loop in the init function, no problems there. But I can't figure out a way to print the fields individually in the template, since I don't know the whole name of each field. If this were my only problem I could just use the form.as_p syntax, no biggie. But I would also like to add some html to the beginning of each set of fields, so that the result would be:
Add values 1:
field_name_1
field_email_1
Add values 2:
field_name_2
field_email_2
Add values 3:
field_name_3
field_email_3
However, I haven't found a way to insert arbitrary html into a form in Django code, similar to #markup in Drupal forms. So:
Is there a way to print the fields individually so I can put the extra html in the template? (What I am missing here is the exact syntax)
If not, how do I insert the extra html into the form?
Do you mean something like this in the template?:
{% for field in form %}
<div class="fieldWrapper">
{{ field.errors }}
{{ field.label_tag }}: {{ field }}
</div>
{% endfor %}
(from the Django documentation: https://docs.djangoproject.com/en/dev/topics/forms/?from=olddocs#looping-over-hidden-and-visible-fields )
You could render the header with something like:
Add values {{forloop.counter}}:

Resources