Show email on customer layout

Torsten Högel

New Member
Hey there,

I wanted to embed Intercom into the customer layout.

I used the code:

<?php echo ($fullName = Yii::app()->customer->getModel()->getFullName()) ? CHtml::encode($fullName) : Yii::t('app', 'Welcome');?>

for inputting the name into the variable, but I can't seem to get the email shown in a similar way... do I have to create a ruction, or is there an easier way?

P.S.: I've searched in the profile layout because the email of the customer is shown there, but with no luck...
 
That worked perfect! Thank you. The code I use is: (If anybody want to use it change YOURAPPID to the app id of your intercom project.)

<script>
window.intercomSettings = {
app_id: "YOURAPPID",
name: "<?php echo Yii::app()->customer->getModel()->getFullName();?>", // Full name
email: "<?php echo Yii::app()->customer->getModel()->email;?>" // Email address
};
</script>
<script>(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',w.intercomSettings);}else{var d=document;var i=function(){i.c(arguments);};i.q=[];i.c=function(args){i.q.push(args);};w.Intercom=i;var l=function(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/YOURAPPID';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);};if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})();</script>
 
Ok, so don't do that.
Create a file called init-custom.php in the /apps/ folder and put this into it:
PHP:
<?php

Yii::app()->hooks->addAction('layout_footer_html', function(){
    if (!Yii::app()->apps->isAppName('customer') || !Yii::app()->customer->getModel()) {
        return;
    }
    ?>
    <script>
    window.intercomSettings = {
    app_id: "YOURAPPID",
    name: "<?php echo Yii::app()->customer->getModel()->getFullName();?>", // Full name
    email: "<?php echo Yii::app()->customer->getModel()->email;?>" // Email address
    };
    </script>
    <script>(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',w.intercomSettings);}else{var d=document;var i=function(){i.c(arguments);};i.q=[];i.c=function(args){i.q.push(args);};w.Intercom=i;var l=function(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/YOURAPPID';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);};if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})();</script>
    <?php
});

This uses this action hook: https://hooks-docs.mailwizz.com/actions.php?keyword=layout_footer_html which means when you upgrade mailwizz, you'll keep your changes ;)

Check out the hooks site for more info. But generally speaking, you never edit core files, but do changes using hooks.
 
Back
Top