1

OK SO I am making a custom module for our magento 2 store.

I have created a module which displays a " Download Product PDF Link " on every product page. But I need to make the link open a new page in a new tab when it is clicked.

My Layout XML located : Modzinc/dynamicpdf/View/frontend/layout/catalogue_product_view.xml

<?xml version="1.0"?>
<body>
<referenceContainer name="product.info.social">
    <block class="Modzinc\Productpdf\Block\Product\View\Link"
           name="modzinc.dynamicpdf.link"
           template="Modzinc_Productpdf::product/view/link.phtml"
           after="-">
    </block>
</referenceContainer>
</body>

MY Template File located at :

<?php



$linkTitle = $this->helper('Modzinc\Productpdf\Helper\Data')->getConfig('dynamicpdf/general/linkText');
$linkTextColor = $this->helper('Modzinc\Productpdf\Helper\Data')->getConfig('dynamicpdf/general/linkTextColor');
$linkBGColor = $this->helper('Modzinc\Productpdf\Helper\Data')->getConfig('dynamicpdf/general/linkBGColor');
$linkImage  = $this->helper('Modzinc\Productpdf\Helper\Data')->getConfig('dynamicpdf/general/linkImage');

###TODO make this more dynmic
$linkImage = "http://www.modzinc.co.uk/pub/media/modzinc/dynamicpdf/" .$linkImage;

##style the link and image properly

echo "<a class='action primary' style='background-color:$linkBGColor;color:$linkTextColor;'>";
if($linkImage!='') {
    echo "<img src='$linkImage'/>";
}

echo "$linkTitle </a>";

This all works great and produces the following in the following link as shown here : enter image description here

Now this is where I am stuck. I need to create a new page opens as "target_blank" in the browser and then I will use my custom code to generate a nice dynamic pdf for the product details.

If this was just a pure PHP application I would do something like this

"Download Product PDF";

And then I would generate the PDF on the pdfMaker.php page .

So I guess my question is how can I make my link open a new page in magento and also install this page when my module is uploaded.

Any pointers will be greatly appreciated

Barry Connolly
  • 404
  • 1
  • 7
  • 15

1 Answers1

0

use target='_blank' will open link in new tab

echo "<a class='action primary' style='background-color:$linkBGColor;color:$linkTextColor;' target='_blank'>";
if($linkImage!='') {
    echo "<img src='$linkImage'/>";
}

echo "$linkTitle </a>";

For creating new page

Create frontend router

app/code/QaisarSatti/HelloWorld/etc/frontend/routes.xml

<?xml version="1.0"?>
<!--/**
* Simple Hello World Module
*
* @category QaisarSatti
* @package QaisarSatti_HelloWorld
* @author Muhammad Qaisar Satti
* @Email qaisarssatti@gmail.com
*
*/ -->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route id="helloworld" frontName="helloworld">
<module name="QaisarSatti_HelloWorld" />
</route>
</router>
</config>

Create controller

app/code/QaisarSatti/HelloWorld/Controller/Index/Index.php

<?php
/**
* Simple Hello World Module
*
* @category QaisarSatti
* @package QaisarSatti_HelloWorld
* @author Muhammad Qaisar Satti
* @Email qaisarssatti@gmail.com
*
*/
namespace QaisarSatti\HelloWorld\Controller\Index;
class Index extends \Magento\Framework\App\Action\Action
{
public function execute()
{
echo "dsfds";
}
}

How to create CUSTOM extension in magento 2.1.6?

Qaisar Satti
  • 32,469
  • 18
  • 85
  • 137