I'm building a web page using Poole/Lanyon. A file uses a multi-level or nested site variable like {{ site.github.repo }}.
As a novice in Ruby and YAML, I'm not sure how I should declare this value in _config.yml. I tried like this in _config.yml:
github:
- repo: 'https://github.com/foo/bar.github.io'
It was not working: an empty string is returned when I use {{ site.github.repo }}. I'm however able to get {{ site.github }} like this:
{"repo"=>"https://github.com/foo/bar.github.io"}
In order to use site.github.repo, how should I define this variable in the configuration file?
In your _config.yml, you've defined site.github as a list, and you're trying to access it as an associative array, hence the problem.
If you want to access it as an associative array, you'll need to redefine your variable as such:
github:
repo: 'https://github.com/foo/bar.github.io'
As of writing this, I don't think that the Wikipedia sections I have linked to are super clear, but you can refer to their sample document, which I think showcases YAML's possibilities pretty well.
Related
Is there a way to define custom "Actions" (like range, if, block, etc) with either text or html go templates. I would like to achieve something like the following:
{{ component "blog_post" . }}
{{ template "title" . }}
{{ component "content" . }}
My Content
{{ end }}
{{ end }}
Where "component" is my custom action.
I have achieved the above functionally using custom functions but it is pretty clunky and hard to read. I am particularly interested in the ability to use a custom action that takes both a normal argument (such as .) as well as arbitrary "children" (much like a react component).
This is not possible in the current implementation of Go templates.
Actions are handled by the internal text/template/parse package, and are all defined in https://golang.org/src/text/template/parse/node.go. You will find that there is no mechanism for creating new actions, as the Tree.action method in parse.go has a hardcoded switch case for them.
This is sad because the text/template package has a lot of missed opportunities for reusable features. For example, there's an entire built-in LISP parser that's unusable unless you use it through the template parser.
Wondering if it is possible to manipulate the output of a #yield in Laravel? In short I have a title in my child template that I would like to set some id's with to make them unique. I know I could just create another #section('id', 'asdf') but rather not have to worry users with that especially since the title has to be unique anyways...
Could not find anything that says this is possible?
Example (which fails) but what I am essentially trying to do:
id="{{Str::kebab(#yield('title'))}}-preview-tab"
#yield gets replaced with a PHP echo statement so that is not what you want. If you want the content of a section you can grab it from the View Factory:
$__env->getSection($name, $default)
Or even calling yieldContent:
$__env->yieldContent($section, $default)
So you could try:
{{ Str::kebab($__env->getSection('title', 'some default if you want')) }}
If you have any issues with that, try the yieldContent method.
I am trying to build the name of a var dynamically by concatenating the value of a variable and adding some string afterwards, as I add these variable in runtime. Something like the following should work but it does not.
th:text="${__#{myClass.getA().getB()}+'-result'__}"
Is this even possible to do? I dont know the name of the variable, I can only construct it like this unfortunately.
Yes, that is possible, Thymeleaf supports expression preprocessing:
Let's start with some examples:
The message(i18n) expressions should be referenced using the # character. So let's suppose you have the message.key in your translation file. To reference it in Thymeleaf you will have to use
th:text="#{message.key}"
In your scenario your key name is generated dynamically based on a variable so for preprocessing it in thymeleaf you need to use two underscores __
Let's suppose in your context you have a model variable called myModelVariable with a method messagePrefix(). Our example becomes:
th:text="#{__${myModelVariable.messagePrefix()}__}"
This means the myModelVariable.messagePrefix() will be processed first and the result will be used as the key name which will be then resolved to a nice user friendly message.
And if you also want to add a static part at the end of it will look like this:
th:text="#{__${myModelVariable.messagePrefix()}__}+'*'"
Even the key can contain a static part so this is also accepted:
th:text="#{__${myModelVariable.messagePrefix()}__.staticsuffix}+'*'"
More info you can find in the section 2.7 here:
https://www.thymeleaf.org/doc/articles/standarddialect5minutes.html
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)) }}
I have a dynamically generated Smarty variable in PHP. I want to access it with name ,
Say for example there is a smarty variable {$asdf} which was generated dynamically and i have an array that has 'asdf' i want to use this array and access {$asdf}.
{$asdf} prints a input element [rendered] ;
$array = array('asdf');
{foreach from=$array item=x}
{$x}
{/foreach}
//but {$x} is not giving renderend input instead it is giving $asdf
where am i going wrong?
It is generally atypical to do this type of work in a template file. You should separate your template and logic as much as possible -- there's no plausible scenario in which you could not simply prepare the needed variables for your template in php and pass them on to the template in a useable structure.
That said, it is possible. Within a template, all variables that were passed to the template are accessible in an array, Smarty::_tpl_vars. Within a template, one may interact with this array using the {php}{/php} tags, where it can be referenced via $this --
{php}
$unknownValue = $this->_tpl_vars[
$this->_tpl_vars['known_key']
];
// for example...
$this->_tpl_vars['magicalValue'] = $unknownValue;
{/php}
Magic: {$magicalValue}
I cannot reiterate enough, however, that it is generally bad practice to place such logic inside a template.