how to get block data on phtml template in magento 2magento 2 how to call any block function in phtmlI created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?main.CRITICAL: Plugin class doesn't existMagento 2: How to override newsletter Subscriber modelPrice not getting updated for second product…Form is not displayed on panel admin Magento 2Magento 2: Add a product to the cart programmaticallyMagento offline custom Payment method with drop down listMagento 2 Create dynamic array From different Model Collection to use in multi select in gridMagento 2.3 Can't view module's front end page output?

Why did they wait for Quill to arrive?

Compactness in normed vector spaces.

Why do the Avengers care about returning these items in Endgame?

Is there a need for better software for writers?

Do Rabbis admit emotional involvement in their rulings?

A Latin text with dependency tree

Are double contractions formal? Eg: "couldn't've" for "could not have"

Does STATISTICS IO output include Version Store reads?

How do I minimise waste on a flight?

how to find out if there's files in a folder and exit accordingly (in KSH)

What can cause an unfrozen indoor copper drain pipe to crack?

Has there been evidence of any other gods?

Has everyone forgotten about wildfire?

How did Captain Marvel know where to find these characters?

Pre-1993 comic in which Wolverine's claws were turned to rubber?

Ugin's Conjurant vs. un-preventable damage

Is it a Munchausen Number?

How do carbureted and fuel injected engines compare in high altitude?

Are on’yomi words loanwords?

How to handle DM constantly stealing everything from sleeping characters?

"Estrontium" on poster

How can it be that ssh somename works, while nslookup somename does not?

I might have messed up in the 'Future Work' section of my thesis

Does a surprised creature obey the 1st level spell Command?



how to get block data on phtml template in magento 2


magento 2 how to call any block function in phtmlI created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?main.CRITICAL: Plugin class doesn't existMagento 2: How to override newsletter Subscriber modelPrice not getting updated for second product…Form is not displayed on panel admin Magento 2Magento 2: Add a product to the cart programmaticallyMagento offline custom Payment method with drop down listMagento 2 Create dynamic array From different Model Collection to use in multi select in gridMagento 2.3 Can't view module's front end page output?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















what is missing in my code block data not shown in phtml template



block page



namespace xxxxTrailsBlock;

use MagentoFrameworkViewElementTemplate;
use MagentoFrameworkViewElementTemplateContext;
use xxxxTrailsModelResourceModelPostCollection as PostCollection;
use xxxTrailsModelResourceModelPostCollectionFactory as PostCollectionFactory;
use xxxTrailsModelPost;

class Users extends Template

/**
* CollectionFactory
* @var null


and phtml template



 <?php

// var_dump(getUserAllTrails());
var_dump($block->getUsers());

// foreach ($block->getTrails() as $post)
// echo $post->getTrailsName();
//
//
?>


xml file



<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">


<block class="xxxTrailsBlockUsers"
name="post.users"
template="xxx_Trails::post/trail.phtml" />
</referenceContainer>
</body>
</page>


controller page



namespace xxxTrailsControllerPost;
use MagentoFrameworkAppActionAction;
use MagentoFrameworkViewResultPageFactory;
use MagentoFrameworkViewResultPage;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkExceptionLocalizedException;
use MagentoFrameworkRegistry;


class Users extends Action
{
const REGISTRY_KEY_POST_ID = 'xxxx_trails_trails_id';

/**
* Core registry
* @var Registry
*
*/
protected $customerSession;


protected $_coreRegistry;

/**
* @var PageFactory
*/
protected $_resultPageFactory;

/**
* @param Context $context
* @param Registry $coreRegistry
* @param PageFactory $resultPageFactory
*
* @codeCoverageIgnore
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Context $context,
Registry $coreRegistry,
PageFactory $resultPageFactory





)
parent::__construct(
$context
);
$this->_coreRegistry = $coreRegistry;
$this->_resultPageFactory = $resultPageFactory;





/**
* Saves the blog id to the register and renders the page
* @return Page
* @throws LocalizedException
*/

public function execute()



$blockInstance = $this->_objectManager->get('xxxxTrailsBlockUsers');
$blockInstance->getUsers();

$this->_coreRegistry->register(self::REGISTRY_KEY_POST_ID, (int)$this->_request->getParam('id'));
$resultPage = $this->_resultPageFactory->create();
return $resultPage;











share|improve this question
























  • var_dump($postCollection->getItems()); die(); data are show

    – Nitesh Kumar Singh
    May 22 '18 at 9:17











  • Can you share the xml code from where you are calling the phtml?

    – Sukumar Gorai
    May 22 '18 at 9:18











  • can you simply try with this code in your template file var_dump($block->getUsers());

    – Shashank Kumrawat
    Oct 17 '18 at 2:05











  • are you sure your block is not being called from your template file..try to die('test''); in your block file.

    – Shashank Kumrawat
    Oct 17 '18 at 2:18











  • magento.stackexchange.com/questions/121364/… try this

    – Himanshu
    Oct 17 '18 at 6:13

















1















what is missing in my code block data not shown in phtml template



block page



namespace xxxxTrailsBlock;

use MagentoFrameworkViewElementTemplate;
use MagentoFrameworkViewElementTemplateContext;
use xxxxTrailsModelResourceModelPostCollection as PostCollection;
use xxxTrailsModelResourceModelPostCollectionFactory as PostCollectionFactory;
use xxxTrailsModelPost;

class Users extends Template

/**
* CollectionFactory
* @var null


and phtml template



 <?php

// var_dump(getUserAllTrails());
var_dump($block->getUsers());

// foreach ($block->getTrails() as $post)
// echo $post->getTrailsName();
//
//
?>


xml file



<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">


<block class="xxxTrailsBlockUsers"
name="post.users"
template="xxx_Trails::post/trail.phtml" />
</referenceContainer>
</body>
</page>


controller page



namespace xxxTrailsControllerPost;
use MagentoFrameworkAppActionAction;
use MagentoFrameworkViewResultPageFactory;
use MagentoFrameworkViewResultPage;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkExceptionLocalizedException;
use MagentoFrameworkRegistry;


class Users extends Action
{
const REGISTRY_KEY_POST_ID = 'xxxx_trails_trails_id';

/**
* Core registry
* @var Registry
*
*/
protected $customerSession;


protected $_coreRegistry;

/**
* @var PageFactory
*/
protected $_resultPageFactory;

/**
* @param Context $context
* @param Registry $coreRegistry
* @param PageFactory $resultPageFactory
*
* @codeCoverageIgnore
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Context $context,
Registry $coreRegistry,
PageFactory $resultPageFactory





)
parent::__construct(
$context
);
$this->_coreRegistry = $coreRegistry;
$this->_resultPageFactory = $resultPageFactory;





/**
* Saves the blog id to the register and renders the page
* @return Page
* @throws LocalizedException
*/

public function execute()



$blockInstance = $this->_objectManager->get('xxxxTrailsBlockUsers');
$blockInstance->getUsers();

$this->_coreRegistry->register(self::REGISTRY_KEY_POST_ID, (int)$this->_request->getParam('id'));
$resultPage = $this->_resultPageFactory->create();
return $resultPage;











share|improve this question
























  • var_dump($postCollection->getItems()); die(); data are show

    – Nitesh Kumar Singh
    May 22 '18 at 9:17











  • Can you share the xml code from where you are calling the phtml?

    – Sukumar Gorai
    May 22 '18 at 9:18











  • can you simply try with this code in your template file var_dump($block->getUsers());

    – Shashank Kumrawat
    Oct 17 '18 at 2:05











  • are you sure your block is not being called from your template file..try to die('test''); in your block file.

    – Shashank Kumrawat
    Oct 17 '18 at 2:18











  • magento.stackexchange.com/questions/121364/… try this

    – Himanshu
    Oct 17 '18 at 6:13













1












1








1








what is missing in my code block data not shown in phtml template



block page



namespace xxxxTrailsBlock;

use MagentoFrameworkViewElementTemplate;
use MagentoFrameworkViewElementTemplateContext;
use xxxxTrailsModelResourceModelPostCollection as PostCollection;
use xxxTrailsModelResourceModelPostCollectionFactory as PostCollectionFactory;
use xxxTrailsModelPost;

class Users extends Template

/**
* CollectionFactory
* @var null


and phtml template



 <?php

// var_dump(getUserAllTrails());
var_dump($block->getUsers());

// foreach ($block->getTrails() as $post)
// echo $post->getTrailsName();
//
//
?>


xml file



<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">


<block class="xxxTrailsBlockUsers"
name="post.users"
template="xxx_Trails::post/trail.phtml" />
</referenceContainer>
</body>
</page>


controller page



namespace xxxTrailsControllerPost;
use MagentoFrameworkAppActionAction;
use MagentoFrameworkViewResultPageFactory;
use MagentoFrameworkViewResultPage;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkExceptionLocalizedException;
use MagentoFrameworkRegistry;


class Users extends Action
{
const REGISTRY_KEY_POST_ID = 'xxxx_trails_trails_id';

/**
* Core registry
* @var Registry
*
*/
protected $customerSession;


protected $_coreRegistry;

/**
* @var PageFactory
*/
protected $_resultPageFactory;

/**
* @param Context $context
* @param Registry $coreRegistry
* @param PageFactory $resultPageFactory
*
* @codeCoverageIgnore
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Context $context,
Registry $coreRegistry,
PageFactory $resultPageFactory





)
parent::__construct(
$context
);
$this->_coreRegistry = $coreRegistry;
$this->_resultPageFactory = $resultPageFactory;





/**
* Saves the blog id to the register and renders the page
* @return Page
* @throws LocalizedException
*/

public function execute()



$blockInstance = $this->_objectManager->get('xxxxTrailsBlockUsers');
$blockInstance->getUsers();

$this->_coreRegistry->register(self::REGISTRY_KEY_POST_ID, (int)$this->_request->getParam('id'));
$resultPage = $this->_resultPageFactory->create();
return $resultPage;











share|improve this question
















what is missing in my code block data not shown in phtml template



block page



namespace xxxxTrailsBlock;

use MagentoFrameworkViewElementTemplate;
use MagentoFrameworkViewElementTemplateContext;
use xxxxTrailsModelResourceModelPostCollection as PostCollection;
use xxxTrailsModelResourceModelPostCollectionFactory as PostCollectionFactory;
use xxxTrailsModelPost;

class Users extends Template

/**
* CollectionFactory
* @var null


and phtml template



 <?php

// var_dump(getUserAllTrails());
var_dump($block->getUsers());

// foreach ($block->getTrails() as $post)
// echo $post->getTrailsName();
//
//
?>


xml file



<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">


<block class="xxxTrailsBlockUsers"
name="post.users"
template="xxx_Trails::post/trail.phtml" />
</referenceContainer>
</body>
</page>


controller page



namespace xxxTrailsControllerPost;
use MagentoFrameworkAppActionAction;
use MagentoFrameworkViewResultPageFactory;
use MagentoFrameworkViewResultPage;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkExceptionLocalizedException;
use MagentoFrameworkRegistry;


class Users extends Action
{
const REGISTRY_KEY_POST_ID = 'xxxx_trails_trails_id';

/**
* Core registry
* @var Registry
*
*/
protected $customerSession;


protected $_coreRegistry;

/**
* @var PageFactory
*/
protected $_resultPageFactory;

/**
* @param Context $context
* @param Registry $coreRegistry
* @param PageFactory $resultPageFactory
*
* @codeCoverageIgnore
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Context $context,
Registry $coreRegistry,
PageFactory $resultPageFactory





)
parent::__construct(
$context
);
$this->_coreRegistry = $coreRegistry;
$this->_resultPageFactory = $resultPageFactory;





/**
* Saves the blog id to the register and renders the page
* @return Page
* @throws LocalizedException
*/

public function execute()



$blockInstance = $this->_objectManager->get('xxxxTrailsBlockUsers');
$blockInstance->getUsers();

$this->_coreRegistry->register(self::REGISTRY_KEY_POST_ID, (int)$this->_request->getParam('id'));
$resultPage = $this->_resultPageFactory->create();
return $resultPage;








magento2 magento-2.1 module blocks collection






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 22 '18 at 9:24







Nitesh Kumar Singh

















asked May 22 '18 at 9:13









Nitesh Kumar SinghNitesh Kumar Singh

5613




5613












  • var_dump($postCollection->getItems()); die(); data are show

    – Nitesh Kumar Singh
    May 22 '18 at 9:17











  • Can you share the xml code from where you are calling the phtml?

    – Sukumar Gorai
    May 22 '18 at 9:18











  • can you simply try with this code in your template file var_dump($block->getUsers());

    – Shashank Kumrawat
    Oct 17 '18 at 2:05











  • are you sure your block is not being called from your template file..try to die('test''); in your block file.

    – Shashank Kumrawat
    Oct 17 '18 at 2:18











  • magento.stackexchange.com/questions/121364/… try this

    – Himanshu
    Oct 17 '18 at 6:13

















  • var_dump($postCollection->getItems()); die(); data are show

    – Nitesh Kumar Singh
    May 22 '18 at 9:17











  • Can you share the xml code from where you are calling the phtml?

    – Sukumar Gorai
    May 22 '18 at 9:18











  • can you simply try with this code in your template file var_dump($block->getUsers());

    – Shashank Kumrawat
    Oct 17 '18 at 2:05











  • are you sure your block is not being called from your template file..try to die('test''); in your block file.

    – Shashank Kumrawat
    Oct 17 '18 at 2:18











  • magento.stackexchange.com/questions/121364/… try this

    – Himanshu
    Oct 17 '18 at 6:13
















var_dump($postCollection->getItems()); die(); data are show

– Nitesh Kumar Singh
May 22 '18 at 9:17





var_dump($postCollection->getItems()); die(); data are show

– Nitesh Kumar Singh
May 22 '18 at 9:17













Can you share the xml code from where you are calling the phtml?

– Sukumar Gorai
May 22 '18 at 9:18





Can you share the xml code from where you are calling the phtml?

– Sukumar Gorai
May 22 '18 at 9:18













can you simply try with this code in your template file var_dump($block->getUsers());

– Shashank Kumrawat
Oct 17 '18 at 2:05





can you simply try with this code in your template file var_dump($block->getUsers());

– Shashank Kumrawat
Oct 17 '18 at 2:05













are you sure your block is not being called from your template file..try to die('test''); in your block file.

– Shashank Kumrawat
Oct 17 '18 at 2:18





are you sure your block is not being called from your template file..try to die('test''); in your block file.

– Shashank Kumrawat
Oct 17 '18 at 2:18













magento.stackexchange.com/questions/121364/… try this

– Himanshu
Oct 17 '18 at 6:13





magento.stackexchange.com/questions/121364/… try this

– Himanshu
Oct 17 '18 at 6:13










2 Answers
2






active

oldest

votes


















0














Suppose if your route is xxxx and controller file name is Index.php and method name is Index then you need to create xxxx_index_index.xml file under this path xxxxTrailsviewfrontendlayout.



<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">

<body>
<referenceContainer name="content">
<block class="xxxxTrailsBlockUsers" name="test-block" template="test.phtml" />
</referenceContainer>
</body>
</page>


Or you can call direct block in your file this way also



<?php
$blockObj= $block->getLayout()->createBlock('xxxxTrailsBlockUsers');
echo $blockObj->getUsers();
?>





share|improve this answer

























  • I want to print on a template or not on a controller

    – Nitesh Kumar Singh
    May 22 '18 at 10:59











  • <?php var_dump($block->getUsers()); ?> Phtml template

    – Nitesh Kumar Singh
    May 22 '18 at 10:59












  • Above code for you can call block methods in phtml file.

    – Yogesh
    May 22 '18 at 11:00











  • on controller and block page working but on a template not working

    – Nitesh Kumar Singh
    May 22 '18 at 11:02












  • array is empty on template

    – Nitesh Kumar Singh
    May 22 '18 at 11:05


















0














You did the mistake. You can't render a block using below code from controller




 $blockInstance = $this->_objectManager->get('xxxxTrailsBlockUsers');
$blockInstance->getUsers()



first ,you need to call layout then render the block via layout file or code.






share|improve this answer

























  • I want to print on a template or not on a controller.

    – Nitesh Kumar Singh
    May 22 '18 at 10:58











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f226945%2fhow-to-get-block-data-on-phtml-template-in-magento-2%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Suppose if your route is xxxx and controller file name is Index.php and method name is Index then you need to create xxxx_index_index.xml file under this path xxxxTrailsviewfrontendlayout.



<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">

<body>
<referenceContainer name="content">
<block class="xxxxTrailsBlockUsers" name="test-block" template="test.phtml" />
</referenceContainer>
</body>
</page>


Or you can call direct block in your file this way also



<?php
$blockObj= $block->getLayout()->createBlock('xxxxTrailsBlockUsers');
echo $blockObj->getUsers();
?>





share|improve this answer

























  • I want to print on a template or not on a controller

    – Nitesh Kumar Singh
    May 22 '18 at 10:59











  • <?php var_dump($block->getUsers()); ?> Phtml template

    – Nitesh Kumar Singh
    May 22 '18 at 10:59












  • Above code for you can call block methods in phtml file.

    – Yogesh
    May 22 '18 at 11:00











  • on controller and block page working but on a template not working

    – Nitesh Kumar Singh
    May 22 '18 at 11:02












  • array is empty on template

    – Nitesh Kumar Singh
    May 22 '18 at 11:05















0














Suppose if your route is xxxx and controller file name is Index.php and method name is Index then you need to create xxxx_index_index.xml file under this path xxxxTrailsviewfrontendlayout.



<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">

<body>
<referenceContainer name="content">
<block class="xxxxTrailsBlockUsers" name="test-block" template="test.phtml" />
</referenceContainer>
</body>
</page>


Or you can call direct block in your file this way also



<?php
$blockObj= $block->getLayout()->createBlock('xxxxTrailsBlockUsers');
echo $blockObj->getUsers();
?>





share|improve this answer

























  • I want to print on a template or not on a controller

    – Nitesh Kumar Singh
    May 22 '18 at 10:59











  • <?php var_dump($block->getUsers()); ?> Phtml template

    – Nitesh Kumar Singh
    May 22 '18 at 10:59












  • Above code for you can call block methods in phtml file.

    – Yogesh
    May 22 '18 at 11:00











  • on controller and block page working but on a template not working

    – Nitesh Kumar Singh
    May 22 '18 at 11:02












  • array is empty on template

    – Nitesh Kumar Singh
    May 22 '18 at 11:05













0












0








0







Suppose if your route is xxxx and controller file name is Index.php and method name is Index then you need to create xxxx_index_index.xml file under this path xxxxTrailsviewfrontendlayout.



<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">

<body>
<referenceContainer name="content">
<block class="xxxxTrailsBlockUsers" name="test-block" template="test.phtml" />
</referenceContainer>
</body>
</page>


Or you can call direct block in your file this way also



<?php
$blockObj= $block->getLayout()->createBlock('xxxxTrailsBlockUsers');
echo $blockObj->getUsers();
?>





share|improve this answer















Suppose if your route is xxxx and controller file name is Index.php and method name is Index then you need to create xxxx_index_index.xml file under this path xxxxTrailsviewfrontendlayout.



<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">

<body>
<referenceContainer name="content">
<block class="xxxxTrailsBlockUsers" name="test-block" template="test.phtml" />
</referenceContainer>
</body>
</page>


Or you can call direct block in your file this way also



<?php
$blockObj= $block->getLayout()->createBlock('xxxxTrailsBlockUsers');
echo $blockObj->getUsers();
?>






share|improve this answer














share|improve this answer



share|improve this answer








edited May 22 '18 at 9:39

























answered May 22 '18 at 9:31









YogeshYogesh

9321923




9321923












  • I want to print on a template or not on a controller

    – Nitesh Kumar Singh
    May 22 '18 at 10:59











  • <?php var_dump($block->getUsers()); ?> Phtml template

    – Nitesh Kumar Singh
    May 22 '18 at 10:59












  • Above code for you can call block methods in phtml file.

    – Yogesh
    May 22 '18 at 11:00











  • on controller and block page working but on a template not working

    – Nitesh Kumar Singh
    May 22 '18 at 11:02












  • array is empty on template

    – Nitesh Kumar Singh
    May 22 '18 at 11:05

















  • I want to print on a template or not on a controller

    – Nitesh Kumar Singh
    May 22 '18 at 10:59











  • <?php var_dump($block->getUsers()); ?> Phtml template

    – Nitesh Kumar Singh
    May 22 '18 at 10:59












  • Above code for you can call block methods in phtml file.

    – Yogesh
    May 22 '18 at 11:00











  • on controller and block page working but on a template not working

    – Nitesh Kumar Singh
    May 22 '18 at 11:02












  • array is empty on template

    – Nitesh Kumar Singh
    May 22 '18 at 11:05
















I want to print on a template or not on a controller

– Nitesh Kumar Singh
May 22 '18 at 10:59





I want to print on a template or not on a controller

– Nitesh Kumar Singh
May 22 '18 at 10:59













<?php var_dump($block->getUsers()); ?> Phtml template

– Nitesh Kumar Singh
May 22 '18 at 10:59






<?php var_dump($block->getUsers()); ?> Phtml template

– Nitesh Kumar Singh
May 22 '18 at 10:59














Above code for you can call block methods in phtml file.

– Yogesh
May 22 '18 at 11:00





Above code for you can call block methods in phtml file.

– Yogesh
May 22 '18 at 11:00













on controller and block page working but on a template not working

– Nitesh Kumar Singh
May 22 '18 at 11:02






on controller and block page working but on a template not working

– Nitesh Kumar Singh
May 22 '18 at 11:02














array is empty on template

– Nitesh Kumar Singh
May 22 '18 at 11:05





array is empty on template

– Nitesh Kumar Singh
May 22 '18 at 11:05













0














You did the mistake. You can't render a block using below code from controller




 $blockInstance = $this->_objectManager->get('xxxxTrailsBlockUsers');
$blockInstance->getUsers()



first ,you need to call layout then render the block via layout file or code.






share|improve this answer

























  • I want to print on a template or not on a controller.

    – Nitesh Kumar Singh
    May 22 '18 at 10:58















0














You did the mistake. You can't render a block using below code from controller




 $blockInstance = $this->_objectManager->get('xxxxTrailsBlockUsers');
$blockInstance->getUsers()



first ,you need to call layout then render the block via layout file or code.






share|improve this answer

























  • I want to print on a template or not on a controller.

    – Nitesh Kumar Singh
    May 22 '18 at 10:58













0












0








0







You did the mistake. You can't render a block using below code from controller




 $blockInstance = $this->_objectManager->get('xxxxTrailsBlockUsers');
$blockInstance->getUsers()



first ,you need to call layout then render the block via layout file or code.






share|improve this answer















You did the mistake. You can't render a block using below code from controller




 $blockInstance = $this->_objectManager->get('xxxxTrailsBlockUsers');
$blockInstance->getUsers()



first ,you need to call layout then render the block via layout file or code.







share|improve this answer














share|improve this answer



share|improve this answer








edited May 22 '18 at 10:02









Dhaval Solanki

1,39611032




1,39611032










answered May 22 '18 at 9:30









Amit BeraAmit Bera

60.5k1678178




60.5k1678178












  • I want to print on a template or not on a controller.

    – Nitesh Kumar Singh
    May 22 '18 at 10:58

















  • I want to print on a template or not on a controller.

    – Nitesh Kumar Singh
    May 22 '18 at 10:58
















I want to print on a template or not on a controller.

– Nitesh Kumar Singh
May 22 '18 at 10:58





I want to print on a template or not on a controller.

– Nitesh Kumar Singh
May 22 '18 at 10:58

















draft saved

draft discarded
















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f226945%2fhow-to-get-block-data-on-phtml-template-in-magento-2%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?