How to load a default snippet from a template in sulu? - sulu

I'm trying to use a snippet to store a contact address meant to be displayed in the footer of every page.
Following the doc (https://docs.sulu.io/en/2.3/cookbook/default-snippets.html), I created a snippet template named address in config/templates/snippets/address.xml and defined an area in this file, like this :
<areas>
<area key="footer_address">
<meta>
<title lang="fr">Adresse dans le pied de page</title>
</meta>
</area>
</areas>
I created a snippet from this template in the admin area and assigned it in the "Default snippet" tab.
But when I try to load this snippet with sulu_snippet_load_by_area('footer_address'). I get the following error :
An exception has been thrown during the rendering of a template ("You have requested a non-existent parameter "footer_address".").
If I don't assign the snippet from the admin area, the twig function does not throw an error, but return null.
I must be doing something wrong, but I can't see what :/

It was just a cache issue. I ran bin/websiteconsole cache:clear and it works fine. I was just running bin/adminconsole cache:clear, and it was not enough.

Related

How do I add content for warning macro using storage format?

I'm creating a markdown to confluence tool (using python markdown). I'm having an issue adding content for the warning macro.
The following creates the warning box with the title, but the content is missing.
<ac:structured-macro ac:name="warning">
<ac:parameter ac:name="title">Do Not Modify This Page</ac:parameter>
<ac:rich-text-body><p>
This page is generated by a script. Any changes made
here will be erased the next time this page is
generated.
</p></ac:rich-text-body>
</ac:structured-macro>
The docs for the warning macro don't specify what should be used.
When I edit the warning box in the ui and get body.storage for the page this is what is returned.
<ac:structured-macro ac:name=\"warning\" ac:schema-version=\"1\" ac:macro-id=\"3520f15e-e8af-4b26-bf94-4dbc226d8284\">
<ac:parameter ac:name=\"title\">Do Not Modify This Page</ac:parameter>
<ac:rich-text-body><p>blah frickin blah</p></ac:rich-text-body>
</ac:structured-macro>
I have tried replacing <ac:rich-text-body> with nothing, plain-text-body, body, content and a few others I can't remember. None of these have worked.
Any ideas or pointers?
Adding the macro-id to the definition made it work.
<ac:structured-macro ac:name="warning" ac:macro-id="3520f15e-e8af-4b26-bf94-4dbc226d8284">
<ac:parameter ac:name="title">Do Not Modify This Page</ac:parameter>
<ac:rich-text-body><p>
This page is generated by a script. Any changes made
here will be erased the next time this page is
generated.
</p></ac:rich-text-body>
</ac:structured-macro>

TYPO3 11 Sitepackage Tutorial expected template file Standard/1.html

TL;DR:
The Backend Layouts of the site package tutorial (Default/Standard and Two Columns) do not show up for new pages in Appearance -> Backend Layout. The error message in this thread (1.html) is an artefact of prior Backend Layouts which came from the original old site setup.
Solution:
To make the Backend Layouts of the site package tutorial show up there, I had to edit the root page of the site: Resources -> Include static Page TSconfig (from extensions) and add site-package from the Available Items list.
This can also be achieved without "Resources -> Include static Page TSconfig (from extensions)" but via file ext_localconf.php in the root of the site package extension (gpcf_theme):
<?php
defined('TYPO3_MODE') || die();
$boot = function (string $_EXTKEY): void {
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('
<INCLUDE_TYPOSCRIPT: source="FILE:EXT:'.$_EXTKEY.'/Configuration/TsConfig/Page/Page.tsconfig">
');
};
$boot('gpcf_theme');
unset($boot);
Original Question:
I'm still trying to bring an existing (older) web page into Typo3 11 following the TYPO3 Sitepackage Tutorial.
Currently I get an
"Oops, an error occurred! Code: 202111161210589c32f8c0"
and can't get rid of it whatever I do.
The corresponding entry in the log files is (line breaks added by me):
../../var/log/typo3_61306f633c.log:Tue, 16 Nov 2021 12:10:58 +0000 [ALERT] request="30cc4e082c853"
component="TYPO3.CMS.Frontend.ContentObject.Exception.ProductionExceptionHandler":
Oops, an error occurred! Code: 202111161210589c32f8c0- InvalidTemplateResourceException:
Tried resolving a template file for controller action "Standard->1" in format ".html",
but none of the paths contained the expected template file (Standard/1.html).
The following paths were checked:
/var/www/html/typo3_11/public/typo3conf/ext/gpcf_theme/Resources/Private/Templates/Page/,
in file /var/www/html/typo3_11/vendor/typo3fluid/fluid/src/View/TemplatePaths.php
I can't find the reason of this error, because I have no idea, where the needed template Standard/1.html is requested from.
Is this some kind of hard coded default if nothing else is found?
If this is the case, the real problem is, that my customizations to the Sitepackage Tutorial source code seems to be wrong, but it never produced any different error despite the above one, which isn't really helpful. Ok, this is speculation, because I don't know.
As you can see, the site package was renamed to gpcf_theme, it's available in the backend and applied as root template to the site. No other template is active (AFAIK). A simple newly created test page creates above error.
If I uncomment in Configuration/TypoScript/Setup/Page.typoscript the lines so that:
page = PAGE
page {
typeNum = 0
10 = TEXT
10.value = Hello World!
}
same error, no hello world.
Any idea how to locate the reason for my misery?
Maybe the fix is really simple. Try to go into the backend:
Edit the homepage
To to the "Appearance" tab
Set the Backend Layout for this and subpages
Save your change
There is a good chance that it is working now.
Whats going on?
You can cast this query on your database:
SELECT
uid, pid, title, backend_layout, backend_layout_next_level
FROM
pages;
Here you get a list of pages, some with backend_layout and backend_layout_next_level filled. Most likely your home pages has some values in this fields?
The value of this field is generated by the TSConfig for backend layouts you set in:
https://docs.typo3.org/m/typo3/tutorial-sitepackage/11.5/en-us/ContentMapping/Index.html#dynamic-content-rendering-in-typoscript
This column is then read and processed in your TypoScript:
https://docs.typo3.org/m/typo3/tutorial-sitepackage/11.5/en-us/TypoScriptConfiguration/Index.html#part-1-fluid-template-section
It is explained below the code snippet.
If the 4 steps from the beginning of my answer did not solve your problem, then this are the places to look.
In TSConfig is the definition of the backend layouts, columns, labels and what is written in the pages.backend_layout db-field
DB columns if the value makes sense pagets__<yourTemplateName>
The TypoScript that reads this db-field cuts of the pagets__ takes the rest, adds .html and searches in the paths defined in the TypoScript below.
check if the Folder and Filename of your Template file are correct.
the error message states that the file 1.html is expected in the folder /var/www/html/typo3_11/public/typo3conf/ext/gpcf_theme/Resources/Private/Templates/Page/
as you noted that you have renamed the site package you may have missed some occurrences of the original package name and so some configuration is missing or pointing to nirvana.

Chart Macro In User Macro With Dynamic Content

I was trying to use the Chart macro inside user macro by using the following code,
## #noparams
<ac:structured-macro ac:name="chart">
<ac:parameter ac:name="type">line</ac:parameter>
<ac:parameter ac:name="Tables">Sample</ac:parameter>
</ac:structured-macro>
<table id="sample">
... body goes here...
</table>
I am getting No Data Available in my confluence page. How can I provide the data to a chart macro dynamically?
Andre from atlassian community answered my question. We can make use of <ac:rich-text-body> tag to provide the table. Syntax is following,
<ac:structured-macro ac:name="chart">
<ac:parameter ac:name="type">line</ac:parameter>
<ac:rich-text-body>
here goes the table
</ac:rich-text-body>
</ac:structured-macro>
Full discussion is available in this url.

data-sly-resource error handling in sightly - AEM

data-sly-resource tag allows to refer resource in another component in following way.
<article data-sly-resource="path/to/resource"></article>
We have path/to/resource being taken as part of dialog field by content authors. If the content authors select the path which is not existing by mistake, page becomes inaccessible to content authors, giving HTTP 500 error and there is no other way to correct it without going to CRX. On environments where access to CRX is not there, we cannot delete the incorrect node. Exception in logs is
Caused by: org.apache.sling.scripting.sightly.SightlyException: org.apache.sling.api.resource.ResourceNotFoundException: No resource found
at com.adobe.cq.sightly.WCMScriptHelper.includeResource(WCMScriptHelper.java:143)
at com.adobe.cq.sightly.WCMScriptHelper.includeResource(WCMScriptHelper.java:86)
at com.adobe.cq.sightly.internal.extensions.ResourceExtension.call(ResourceExtension.java:99)
at org.apache.sling.scripting.sightly.impl.engine.runtime.RenderContextImpl.call(RenderContextImpl.java:89)
The out of the box reference component (/libs/foundation/components/reference/reference.jsp) handles this by having a catch block, Content Author can correct path. But that's JSP based not sightly based.
Is there a way to handle this in sightly?
The proper way to handle this is through an Use-API object that will attempt to find the resource and handle any exceptions:
<article data-sly-use.helper="myHelper" data-sly-test="${helper.resource}" data-sly-resource="${helper.resource}"></article>
Passing an actual org.apache.sling.api.resource.Resource to data-sly-resource is possible since SLING-5811, for older versions of HTL/Sightly you will need to pass a path.
Try this syntax, path should given in EL expression:
<article data-sly-resource="${ # path='path/to/resource'}"></article>

how can i place master page inside from tag with runat server

Control 'ctl00_ContentPlaceHolder1_gvTransDetails' of type 'GridView' must be placed inside a form tag with runat=server
how can i place master page inside from tag with runat server
Are you getting this message while exporting the gridview? if this is the case please put the following code snippet :-
public override void VerifyRenderingInServerForm(Control control)
{
/* Verifies that the control is rendered */
}
VerifyRenderingInServerForm function is used to avoid the error like “control must be placed in inside of form tag”. If we set VerifyRenderingInServerForm function then compiler will think that controls rendered before exporting and functionality will work perfectly.
Hope this will work for you.
Thanks