0

I want all information about the theme in my module code how can I grab the theme information.The Theme that I have in my Magento like WordPress we can get all the themes information is it possible here.

This example is useful for magento 1.X what about magento 2.

Mage::getSingleton('core/design_package')->getPackageList(); Mage::getSingleton('core/design_package')->getThemeList();

3
  • this is a bit unclear. What information you want about the theme? Give an example
    – Marius
    Commented Jul 21, 2016 at 6:16
  • @Marius I want theme name and version and all this and i want this info in my module Commented Jul 21, 2016 at 6:28
  • i want to do same thing in magento 2 Commented Jul 21, 2016 at 10:27

2 Answers 2

3

I know it's an old question, but since I was looking for the same thing, for future visitors:

use Magento\Framework\View\Design\Theme\ListInterface;

...

public function __construct(
    ListInterface $themeList
) {
    $this->themeList = $themeList;
}

public function getThemes()
{
    foreach ($this->themeList as $theme) {
        /** @var \Magento\Theme\Model\Theme $theme */
        // do things
    }
}
0

If Someone needs to get the theme id from theme Name, use below

 use \Magento\Theme\Model\ResourceModel\Theme\CollectionFactory;
...

 

    private $themeCollection;
    
        /**
         * Theming constructor.
         * @param Context $context
         * @param CollectionFactory $themeCollection
         */
        public function __construct(
            Context $context,
            CollectionFactory $themeCollection
        ) {
            parent::__construct($context);
            $this->themeCollection = $themeCollection;
        }
    
        /**
         * @param $themeName
         * @return int
         */
    
        public function getThemeId($themeName)
        {
            $collection = $this->themeCollection->create();
            $collection->addFieldToFilter('theme_path', $themeName);
            if ($collection->getSize() > 0) {
                return $collection->getFirstItem()->getThemeId();
            } else {
                return null;
            }
        }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.