External Links with "Open Link in New Window" not opening in new tab/window when using Page List Block

Permalink
https://www.concrete5.org/marketplace/themes/framework/support/external-links-with-open-link-in-new-window-not-opening-in-new-t/

Any thought on this? I have used Page Lists to display External Links many times and have never had issues with them NOT opening in New Tabs. However, in 8.2, it seems to be an issue. Here is how I have used it in the past successfully:http://www.barkingtuna.com/work-portfolio... and here is where it is ISN'T working:http://74.220.215.104/~extrasel/chico2/index.php/solid-surfaces/eng...

barkingtuna
 
barkingtuna replied on at Permalink Reply
barkingtuna
Bump
mnakalay replied on at Permalink Reply
mnakalay
Your links are just missing the target=_Blank attribute. You might have just forgotten to add it to your template.

You could post your template here to have a look.
barkingtuna replied on at Permalink Reply 1 Attachment
barkingtuna
What's interesting though is that it doesn't work with NO TEMPLATE selected either, so it doesn't seem to just be the Theme's page list template. I am building the site in Framework theme.

Template below and attached as a TXT file.

<?php
defined('C5_EXECUTE') or die("Access Denied.");
$th = Loader::helper('text');
$c = Page::getCurrentPage();
$dh = Core::make('helper/date'); /* @var $dh \Concrete\Core\Localization\Service\Date */
$i = 0;
?>
<?php if ( $c->isEditMode() && $controller->isBlockEmpty()) { ?>
    <div class="ccm-edit-mode-disabled-item"><?php echo t('Empty Page List Block.')?></div>
<?php } else { ?>
<div class="pagelistwrapper">
   <?php if ($rssUrl): ?>
        <a class="pull-right" href="<?php echo $rssUrl ?>" target="_blank" class="ccm-block-page-list-rss-feed"><i class="fa fa-rss"></i></a>
    <?php endif; ?>
    <?php if ($pageListTitle): ?>
mnakalay replied on at Permalink Best Answer Reply
mnakalay
These 2 lines are responsible for what's happening
$target = ($page->getCollectionPointerExternalLink() != '' && $page->openCollectionPointerExternalLinkInNewWindow()) ? '_blank' : $page->getAttribute('nav_target');
      $target = empty($target) ? '_self' : $target;

So first it checks if it is an external link AND if it is set to open in a new window. If it is, it gives $target the value "_blank".
If it is not an external URL OR it is not set to open in a new window, it looks for a page attribute with a handle of nav_target to decide what to do.

If after all this, $target is still empty (not an external URL set to open in a new window and no attribute nav_target to be found) then it gets the value "_self".

So according to this code, you need to have a page attribute with a value of "_blank" to achieve the desired outcome.

Now if setting an attribute on each page is a pain or you know all your links for that list should open in a new window, you can just remove these 2 lines and simply replace them with
$target = "_blank";


And then it seems the target is omitted in 2 cases so you need to add it back.
Where you find this code:
<?php if (is_object($thumbnail)): ?>
              <h3>
                      <a class="img-bgcover" href="<?php echo $url; ?>" style="height:150px; background: url(<?php
                $tag = $thumbnail->getRelativePath();
                echo $tag;
                ?>) no-repeat center center;-webkit-background-size: cover;
            -moz-background-size: cover;
            -o-background-size: cover;
            background-size: cover;">
                  </a>
                  </h3>
         <?php endif; ?>

Add the target back like this:
<?php if (is_object($thumbnail)): ?>
              <h3>
                      <a class="img-bgcover" href="<?php echo $url; ?>" target="<?php echo $target; ?>" style="height:150px; background: url(<?php
                $tag = $thumbnail->getRelativePath();
                echo $tag;
                ?>) no-repeat center center;-webkit-background-size: cover;
            -moz-background-size: cover;
            -o-background-size: cover;
            background-size: cover;">
                  </a>
                  </h3>
         <?php endif; ?>

And where you see
<?php if ($useButtonForLink): ?>
                <p>
                    <a class="btn btn-default <?php echo $buttonClasses?>" href="<?php echo $url?>"><?php echo $buttonLinkText?></a>
                </p>
                <?php endif; ?>

change it to
<?php if ($useButtonForLink): ?>
                <p>
                    <a class="btn btn-default <?php echo $buttonClasses?>" href="<?php echo $url?>" target="<?php echo $target?>"><?php echo $buttonLinkText?></a>
                </p>
                <?php endif; ?>
barkingtuna replied on at Permalink Reply
barkingtuna
You are the best! I will forward your response to the template developer. Thank you so much!
mnakalay replied on at Permalink Reply
mnakalay
You are very welcome!