I'm using a theme that use background image in template like this:
{% if page.header.background_image != '' %}
{% set background_html = 'style="background-image: url(' ~ page.media.images[page.header.background_image].url ~ ');"' %}
{% else %}
{% set background_html = "" %}
{% endif %}
In other page templates (in admin) I can see upload field, but not in modular - I see only title and order of modules.
I want to take advantage of image upload, but I can find place to put them, nor add it in the modular.yaml in the theme (I don't want to edit modular from the grav installation).
My goal is to edit theme in the manner where I can use the image upload.
As answered in Grav's discourse forum: If themes does not provide a modular.yaml file, it will use the one provided by antimatter, which seems to be the case with your theme. This modular.yaml does not provide a pagemedia field which allows you to add medias.
Thus, you only have two solutions:
Add your own modular.yaml file in themes/yourtheme/blueprints folder and add a pagemedia field
Add your media manually via ftp
Hope it helps
Paul
Related
Is it possible to remove the logo header shown in the web-based output of NelmioApiDocBundle? And if so, how?
I would like to include the output of this endpoint (/api/doc if you're using the default settings) in an existing website. However, that site already has a header, and adding a second header would be a poor user experience IMHO. But I can't find any place in the documentation that describes how to exclude this gloriously 1990s-style piece of web design.
I've provided a screenshot of the default config below, which is what I get when viewing the docs in a tool like Insomnia. As you can see, the green header is covering the page as it scrolls.
Yes, you can do it.
You should override bundle template, say steps bellow :
1 - Create template file in 'templates/bundles/NelmioApiDocBundle/SwaggerUi/index.html.twig'
2 - Put the content bellow :
{% extends '#!NelmioApiDoc/SwaggerUi/index.html.twig' %}
{% block header %}
<a style="text-decoration: none;" id="logo" href="#" target="_blank">
<h1 style="color: black">You personal title</h1>
</a>
{% endblock %}
That's it , we done
I've now tested the answer provided by #Abdelhak-ouaddi, and while it's correct, I realize that I didn't ask the question clearly enough to get the answer I needed. The provided answer does work for changing the CONTENTS of the green header, but it doesn't remove the header entirely.
See this page at the NelmioApiDocBundle GitHub page for details on how to customize the twig template. The actual default template is located in the repo here.
What I found is that you can easily override the {% header %} twig block to change the contents of the header as the accepted answer states, but since the {% header %} tags are INSIDE the <header> HTML tags, doing this can't remove the header entirely.
In order to remove the ENTIRE header, you need to follow the steps in the accepted answer... but instead of just overwriting the {% header %} block, paste in the entire contents of the index.html.twig file. Then, completely delete the <header> HTML tags and everything inside them (including the {% header %} twig tags).
As a bit of extra credit: removing the header entirely leaves you with a large margin above the page title. You can get rid of that by adjusting the <body> tag in your new index.html.twig file to:
<body style="margin: 0px;">
I'm sure there's a cleaner way to do that, but... that's for another ticket.
For the first time, i am working on Symfony widgets.
{% render "EducateToolsBundle:Shared:selectMenu" with {'entity': 'Stores'} %}
its Meaning is SharedController -->selectMenuAction
{% form_theme form 'EducateToolsBundle:shared:_form_theme.html.twig' %}
What is the meaning of this.
From where i am getting the values to this form .?
You must look at selectMenuAction() method in the Shared controller. It is that function that set what template is used. if using the default Symfony coding standards it should be something like selectMenu.html.twig in a Shared sub folder in the Resources/views of the bundle.
You should looks at the documentation first :
https://symfony.com/doc/current/form/form_customization.html
Because we won't teach you symfony here, it's very well explain in the documentation and it is a task too big for us.
In your case theForm.id is the field of the formType we want to displays.
If we want to display the <input> of an form of user lastname we would use
form_widget(userForm.lastname)
form_widget tells symfony to display only the widget (the ) of the id given.
if you want to have a label + input + the errors of the field you could use
form_row(userForm.lastname)
wich is almost equal to
<div>
{{ form_label(form.lastname) }}
{{ form_errors(form.lastname) }}
{{ form_widget(form.lastname) }}
</div>
(it depends of the form theme, but you should read the doc for the details ;) )
I have just setup a apache server and configured twig. I have two template files one called base.html.twig which has the core template elements and dashboard with blocks that correspond to the base.html.twig
dashboard.html.twig
{% extends "base.html.twig" %}
{% block content %}
<h1>Index</h1>
<p class="important">
Welcome on my awesome homepage.
</p>
{% endblock %}
However when I browse to dashboard.html.twig I just see plain html showing all of the code above. Have I misconfigured something?
I am sure it's something simple so I thank you for your help in advance.
You should not directly "browse" to a twig file, it needs to be parsed and rendered by php objects using classes from Twig libraries.
see http://twig.sensiolabs.org/documentation
To use twig you need PHP installed too. Also you would need Twig PHP library to parse twig templates.
Currently I am working on a controller class which should be able to let a customer add an item to a table in a database and view these items (e.g. a movie).
I am using the following twig code:
{% extends 'base.html.twig' %}
{% block body %}
{% if movies|length == 0 %}
There are no movie items available. Add a movie here to get started.
{% elseif movies|length != 0 %}
These are the results: ...
{% endif %}
{% endblock %}
What is the best way to let a user/customer or whatever the case, add an item to the table that needs to be shown? Should I let a user fill a form on the exact same page as the overview template (I personally do not think this is good, as I want to keep purpose of each page seperated) or should I make a different template with a form where the user will be send to (though this takes redirection time, which some users might be getting annoyed by)? As you can see I am using an anchor tag on the word "here". How should I set-up the anchor tag if I am to use a different template for creating records in a table?
As the documentation of Symfony shows the following:
Home
The path says _welcome and I think it refers to the name of the route that points to a certain controller. Would it be best to use this path function and what would I need to add where it now says _welcome (or was I correct one sentence ago)? And why is there an underscore in the given example?
I am asking this question because when I worked with ASP.NET MVC, there was this method called ActionLink() and made me wonder if this is most common use of redirecting, since you could also just add the template file location to the anchor tag href attribute?
If the form to add a new item is small (one text field + one submit button), you could add the form in the same page.
For example :
{% extends 'base.html.twig' %}
{% block body %}
// display your form here
{% if movies|length == 0 %}
There are no movie items available.
{% elseif movies|length != 0 %}
These are the results: ...
{% endif %}
{% endblock %}
But actually it's up to you to decide if you want it to be displayed in the same page or not.
In the case you decide to redirect the user to a new template, especially for the form, you write the name of the route of the correspondant controller :
here
So the code of the controller will be executed and will redirect to the page of your form.
Concerning "_welcome", I don't know why they write it like this. This is more the way to name a layout file than a route name.
I'm using UserFrosting and so far I've been able to import all of the default elements into the home page. However, I've now added a second page but nothing happened when I copied the following code from the home page:
{% include 'common/components/head.html' %}
<rest of code>
{% include 'common/components/main-nav.html' %}
<rest of code>
{% include 'common/components/footer.html' %}
{% include 'common/components/jumbotron-links.html' %}
I then used the following php code:
<?php include("../userfrosting/templates/common/components/head.html"); ?>
Which seems to work but the page only shows this code found within the head.html file:
{% for item in includeCSS(page_group|default("common")) %} {% endfor %} {% for item in includeJSTop(page_group|default("common")) %} {% endfor %}
Which obviously is not very useful!
When I keep the home and page2.php file in the same folder (in localhost/userfrosting/templates/common) then I receive Error 404. When I move the file to the default UserFrosting home page directory (which the home.html file isn't actually in) in localhost/public, I get only the above code.
It seems like I'm missing something quite basic here but would appreciate some help. Thanks.
You are confusing PHP files and template files. UserFrosting uses a front controller pattern along with the Twig templating engine. So, you do not need a separate PHP file for each page. Instead, you should create a new template file for your page:
userfrosting/templates/common/page2.html
{% include 'common/components/head.html' %}
// DO NOT use PHP here - just Twig! See the Twig documentation: http://twig.sensiolabs.org/doc/templates.html
{% include 'common/components/main-nav.html' %}
// More Twig
{% include 'common/components/jumbotron-links.html' %}
{% include 'common/components/footer.html' %}
Then you need to link up a URL with this template. That is done in the controller, public/index.php, for example like this:
// Miscellaneous pages
$app->get('/page2/?', function () use ($app) {
$app->render('common/page2.html', [
'page' => [
'author' => $app->site->author,
'title' => "Page Deuce",
'description' => "This is the second page, aight?",
'alerts' => $app->alerts->getAndClearMessages()
]
]);
});
I highly recommend going through the tutorial on adding a new page: https://learn.userfrosting.com/building-pages
You can also learn more about MVC, Slim, and Twig here: https://learn.userfrosting.com/basics/overview
Feel free to join in chat if you are still having trouble.