1

I created following files,

app/design/frontend/Magestore/Sample/composer.json

{
"name": "magento/sample-module-theme",
"description": "N/A",
"require": {
    "php": "~5.5.0|~5.6.0|~7.0.0",
    "magento/theme-frontend-luma": "~100.0",
    "magento/framework": "~100.0"
},
"type": "magento2-theme",
"version": "1.0.0",
"license": [
    "OSL-3.0",
    "AFL-3.0"
],
"autoload": {
    "files": [ "registration.php" ]
}
}

app/design/frontend/Magestore/Sample/registration.php

\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::THEME,
'frontend/Magestore/sample',
__DIR__

);

app/design/frontend/Magestore/Sample/theme.xml

<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
<title>Magestore Sample Theme</title>
<parent>Magento/luma</parent>
</theme>

app/design/frontend/Magestore/Sample/Magento_Theme/templates/html/header.phtml

<?php
    $welcomeMessage = "Hello";
?>
<?php switch ($block->getShowPart()):
case 'welcome': ?>
    <li class="greet welcome" data-bind="scope: 'customer'">
        <!-- ko if: customer().fullname  -->
        <span data-bind="text: new String('<?php echo $block->escapeHtml(__('Welcome, %1!', '%1'));?>').replace('%1', customer().firstname)">
        </span>
        <!-- /ko -->
        <!-- ko ifnot: customer().fullname  -->
        <span data-bind="html:'<?=$block->escapeHtml($welcomeMessage) ?>'"></span>
        <!-- /ko -->
    </li>
    <script type="text/x-magento-init">
    {
        "*": {
            "Magento_Ui/js/core/app": {
                "components": {
                    "customer": {
                        "component": "Magento_Customer/js/view/customer"
                    }
                }
            }
        }
    }
    </script>
<?php break; ?>

<?php case 'other': ?>
    <?php echo $block->getChildHtml(); ?>
<?php break; ?>

<?php endswitch; ?>

But changes are not reflected?

26
  • Is that the only file in your theme or is your theme fully set up with registration.php ect also? This theme should also then be enabled within admin.
    – harri
    Commented Jun 14, 2017 at 12:14
  • @Harri Above files are only there. Module is enabled.
    – jassi
    Commented Jun 14, 2017 at 12:15
  • Did you created your theme? Commented Jun 14, 2017 at 12:26
  • @S H Patel I want to modify header file.
    – jassi
    Commented Jun 14, 2017 at 12:27
  • Yes but which theme you are used? Commented Jun 14, 2017 at 12:28

3 Answers 3

3

You can edit via admin , Follow Below steps to reach out

Content > Configuration > Main Website/Theme > Header > Welcome Text

1
  • you are right. But I wanted to edit using template file.
    – jassi
    Commented Jun 15, 2017 at 7:04
3

I'm not sure what are you trying to do but as per your listed file maybe you want to assign header.phtml via a custom module.

By default there no specific file for editing Header. It's all done vai XML.

And header container is made in page_layout files.

So if you wish to assign a template file for it then you can add following in your module or in your theme default.xml file.

<referenceBlock name="header" template="Magento_Theme::html/header.phtml">
</referenceBlock>

If you have not created any theme then please follow this tutorial: http://devdocs.magento.com/guides/v2.1/frontend-dev-guide/themes/theme-create.html

And then add that code in your theme default.xml.

Flush cache if enabled and check.

EDIT :

Create app/design/frontend/Magestore/Sample/Magento_Theme/layout/default.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
  <body>
    <referenceBlock name="header" template="Magento_Theme::html/header.phtml"></referenceBlock>
  </body>
</page>

If you just want to edit Default Welcome msg! as shown in following picture

enter image description here Then in backend Go to Content > Configuration as shown in following picture

enter image description here Click on Edit of your applied theme.

enter image description here Then simply edit message here

enter image description here

But if you wish it done it via theme way then Please check my below code

app/design/frontend/Test/base/theme.xml

<?xml version="1.0"?>
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
    <title>Test Base (abstract theme)</title>
    <parent>Magento/blank</parent>
    <media>
        <preview_image/>
    </media>
</theme>

app/design/frontend/Test/base/registration.php

<?php
    \Magento\Framework\Component\ComponentRegistrar::register(
        \Magento\Framework\Component\ComponentRegistrar::THEME,
        'frontend/Test/base',
        __DIR__
    );

app/design/frontend/Test/base/composer.json

{
    "name": "test/theme-frontend-base",
    "description": "N/A",
    "require": {
        "php": "~5.5.0|~5.6.0|~7.0.0",
        "magento/theme-frontend-blank": "100.0.*",
        "magento/framework": "100.0.*"
    },
    "type": "magento2-theme",
    "version": "2.4.0",
    "license": [
        "Proprietary"
    ],
    "autoload": {
        "files": [
            "registration.php"
        ]
    }
}

app/design/frontend/Test/base/Magento_Theme/templates/html/header.phtml

<?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

/**
 * @var \Magento\Theme\Block\Html\Header $block
 */
$welcomeMessage = "Woohoo : " . $block->getWelcome();
?>
<?php switch ($block->getShowPart()):
    case 'welcome': ?>
        <li class="greet welcome" data-bind="scope: 'customer'">
            <!-- ko if: customer().fullname  -->
            <span data-bind="text: new String('<?php echo $block->escapeHtml(__('Welcome, %1!', '%1'));?>').replace('%1', customer().firstname)">
            </span>
            <!-- /ko -->
            <!-- ko ifnot: customer().fullname  -->
            <span data-bind="html:'<?=$block->escapeHtml($welcomeMessage) ?>'"></span>
            <!-- /ko -->
        </li>
        <script type="text/x-magento-init">
        {
            "*": {
                "Magento_Ui/js/core/app": {
                    "components": {
                        "customer": {
                            "component": "Magento_Customer/js/view/customer"
                        }
                    }
                }
            }
        }
        </script>
    <?php break; ?>

    <?php case 'other': ?>
        <?php echo $block->getChildHtml(); ?>
    <?php break; ?>

<?php endswitch; ?>

After all these please execute following commands

php bin/magento cache:flush

sudo chmod -R 777 var pub

Then after in backend I've selected my theme as following picture enter image description here

Then execute following commands

php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy
php bin/magento cache:flush

Just in case in between if you get an permission error then execute following command

sudo chmod -R 777 var pub

Please let me know if you still face any error. enter image description here

3
  • can you specify little more
    – jassi
    Commented Jun 15, 2017 at 7:33
  • @jassi : check my updated answer. Commented Jun 15, 2017 at 8:11
  • still no effect
    – jassi
    Commented Jun 15, 2017 at 8:55
0

This looks like a mix between a module and a theme. Create a theme using this guide as a theme is probably better suited for this purpose:

http://devdocs.magento.com/guides/v2.1/frontend-dev-guide/themes/theme-create.html

You seem like you have done a lot of the files they may just need checking and put within your theme directory and not module.

If you are basing your theme on Magento luma theme replace parent with 'Magento/luma' in theme.xml (as per guide above) Then you can skip the 'Configure Images' and 'Create directories for static files' steps.

Below are examples of main files your are missing from theme and how your files should look. These should be placed within your theme directory 'app/design/frontend/MySpacename/MyTheme'

Registration.php:

<?php
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::THEME,
'frontend/MySpacename/MyTheme',
__DIR__
);

Theme.xml

<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
 <title>MyTheme</title> <!-- your theme's name -->
 <parent>Magento/luma</parent> <!-- the parent theme, in case your theme inherits from an existing theme -->
 <media>
     <preview_image>media/preview.jpg</preview_image> <!-- the path to your theme's preview image -->
 </media>
 </theme>

If everthing has gone correctly then you should be able to activate the theme you have created within Content -> Design -> Configuration -> Slect Your Store view -> Change Applied Theme to Myspacetheme.

Flush cache's once you have selected this new theme.

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.