In magento 2 How to call phtml file in static block - magento2

I have created extension in magento 2 and i want to call content.phtml file from static block (from admin panel). My content template file location is
C:\xampp\htdocs\Magento2\app/code\Surya\Slider\view\frontend\templates\content.phtml
where, magento2 is my project folder, Surya is vendor and Slider is my extension name. I want to call content.phtml file on homepage through static block.
For that I have created one static block called as "slider". Also, i have created widget. But i want to call content.phtml file in static block.

try below code :
{{block class="Surya\Slider\Block\Slideshow" template="Surya_Slider::content.phtml"}}

You can try the following code -
{{block class="Surya\Slider\Block\Slideshow" template="Surya_Slider::content.phtml"}}

If you would like to call template block in CMS static Block or CMS Page in Magento 2, then you can simply write the following code:
The skeleton code to understand :
{{block class="<vendor_name>\<module_name>\Block\<module_name>" name="<your_block_name>" template="<vendor_name>_<module_name>::<tempate_directory>/content.phtml"}}
Exact code :
{{block class="Surya\Slider\Block\Slider" name="slider" template="Surya_Slider::content.phtml"}}

Related

Magento 2 : Is it possible to switch extension from html to phtml

I have an html file and in this file I would like to call some block method
app/design/frontend/Theme/default/Magento_Checkout/web/template/billing-addresses/form.html
So I would like to add something like that :
<?php $store = $block->getStoreCode(); ?>
But the file being an html I can't do that.
My question is : Can I just change the form.html into a form.phtml without breaking anything ?
If I can't, how can I get the value I need ?
Thanks.
No you cant.
.Html files are used for the knockout components, their logic is in the .js files and their data comes from the php files.
.Phtml files for the blocks
If you want to add some extra logic to the html file - check out documentation and other sources about js components.

Get path of FAL media?

Using Fluid Template with tx_news, I need to get the URL of uploaded FAL video.
Currently I have this:
{newsItem.falMedia.0}
Which prints:
GeorgRinger\News\Domain\Model\FileReference:3
I want the output:
fileadmin/user_upload/MyVideo.mp4
newsItem.falMedia seems to be an ObjectStorage. With .0 you are pointing to the first object of it - not any function of it. In the API you can see its functions http://api.typo3.org/typo3cms/current/html/class_t_y_p_o3_1_1_c_m_s_1_1_core_1_1_resource_1_1_file_reference.html or you can debug it in Fluid by using {newsItem.falMedia.0}
Example: {newsItem.falMedia.0.publicUrl} should give you the public path to the file.
If you just need url of image than use following line
{object.image.originalResource.publicUrl}..
TYPO3: get path out of file reference in Extbase
Please refer above link.

Typo3 Extension PHP View

Using the infos in this link:
https://docs.typo3.org/typo3cms/ExtbaseFluidBook/8-Fluid/9-using-php-based-views.html
I try to create an action to output a JSON.
I have a normal controller with the list action:
public function listAction()
{
$storelocators = $this->storelocatorRepository->findAll();
$this->view->assign('storelocators', $storelocators);
}
And in ext/my_storelocator/Classes/View/Storelocator I have a class List.php:
<?
class Tx_MyStorelocator_View_Storelocator_List extends Tx_Extbase_MVC_View_AbstractView {
public function render() {
return 'Hello World';
}
}
All I get is:
Sorry, the requested view was not found.
The technical reason is: No template was found. View could not be resolved for action "list" in class "My\MyStorelocator\Controller\StorelocatorController".
So I guess there is something wrong with the paths. Or where is the Problem?
Edit: Extensioninfos
Vendor: My
key: my_storelocator
controller: NOT SURE (I created it with the extension_builder so I guess my controllers name is Storelocator)
action: list
From my understanding a classname like Tx_MyStorelocator_View_Storelocator_List should be correct. But its not working
You will need to create an empty file for the HTML view for your controller, e.g. Resources/Private/Template/Storelocator/List.html, even if you do not plan to use the HTML view or if you just return the content yourself (which is perfectly fine).
The reason for this is simply technical limitation.
First of all, TYPO3 now has a built-in JSON view, described thoroughly here: https://usetypo3.com/json-view.html. It lets you easily define which properties you'd like to render.
The error message means that your Controller is still pointing to the TemplateView - because thats the error the TemplateView throws if it can't find the defined template file.
You can specify which view to use to render within your controller. You can either set a default view via the $defaultViewObjectName property, like so:
/**
* #var string
*/
protected $defaultViewObjectName = '\TYPO3\CMS\Fluid\View\TemplateView';
You can also set it from within the Controller inside initialization actions like so:
public function initializeExportPDFAction(){
$this->defaultViewObjectName = 'Vendor\Extension\View\FileTransferView';
}
(I have, however, not yet found a way to define the template from within actions, any tips in the comments would be appreciated)
Your path syntax is probably out of date. Instead of writing a render() function in Classes/View/Storelocator/List.php, try writing a listAction() function in a Classes/Controller/StorelocatorController.php file. Extension Builder should have created this file for you, if you made an aggregate model with the usual "list, create, edit ..." and such actions.
Review A journey through the Blog Example and the following chapter, Creating a first extension, for tips.
Keep in mind that there is a mismatch between the documentation and the Extension Builder generated PHP code files. Developing TYPO3 Extensions with Extbase and Fluid has some parts up to date, and other parts still using old syntax.

Template could not be loaded in TYPO3 extension

Am using a new extension build in TYPO3 V4.5.0 and after it installed it in TYPO3 V6.2.x it shows the following error
The template files "/var/www/dev/typo3/typo3conf/ext/my_ext/Resources/Private/Layouts/Suche.html", "/var/www/dev/typo3/typo3conf/ext/my_ext/Resources/Private/Layouts/Suche" could not be loaded.
The layout i s present in the location. and path given also correct in backend..
How can i fix this?
Check so template filename has first letter uppercase.
The rule is that for action named fooBarAction() template file must be named FooBar.html

How can I launch the executeSomething(sfWebRequest $request) in symfony?

I am new to Symfony 1.4
I have a plugin and inside the modules folder I have payment module, and for this, I have the lib folder and the templates folder. In lib I have the BasePaymentComponents.class.php class and in this class I have some functions called with the prefix executeSometing in this way:
public function executeSometing(sfWebRequest $request)
An for each execute I have a specific template in templates folder. The file structure is like that: _something1.php, _something2.php ...
My question is in what moment the executeSometing function from BasePaymentComponents.class.php is actually executed?
I created another template, named _something3.php and set for him the function:
public function executeSometing3(sfWebRequest $request)
actually is not launching the function. Why?
You are using components - you add components to a template - so to execute the Something method in the BasePayment component you would add the following to your template :
<?php include_component('BasePayment', 'something') ?>
Check the docs here -> Inside the view layer <- for more info