Forum

Thread tagged as: Question

Return Full URL

How do you return a full url onto a page from a perch template?

Brandon Livengood

Brandon Livengood 1 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

PerchSystem::set_var('page', perch_page_url(array(
    'include-domain' => true,
), true));

then

<perch:content id="page" type="text" />

That doesn't seem to work? And it is also adding a text field in the control panel in that region too.

Fatal error: Call to undefined function perch_page_url()

Drew McLellan

Drew McLellan 2638 points
Perch Support

Are you running an old version?

This site was out of date and is now updated to the latest. That fixed the error on the front end but it still is not spitting out the url as well as it is showing a text area in the admin.

Drew McLellan

Drew McLellan 2638 points
Perch Support

What does <perch:showall /> give you?

Here is a link where you can see the show all tag output.

https://perch.uisandbox.es/snipcart/brandon.php

Drew McLellan

Drew McLellan 2638 points
Perch Support

So it's being set, but with no value. Can you show me the code you've got in your page?

<div style="float:left;">
    <div style="width:200px; background-color:#eee; border:1px solid #ccc; float:right; margin: 20px; text-align:center; display:inline; "> <p>$<perch:content id="price" type="text" label="Item Price" order="3" /></p>
        <a href="#"
            class="snipcart-add-item"
            data-item-name="<perch:content id="name" type="text" label="Item Name" order="1" />"
            data-item-id="<perch:content id="sku" type="text" label="Item Sku" order="2" />"
            data-item-price="<perch:content id="price" type="text" label="Item Price" order="3" />"
            data-item-url="<perch:content id="page" type="text" />">
        Add to Cart</a>
    <br />
</div>
    <perch:content type="textarea" id="details" label="Product Details" markdown="true" editor="markitup" order="3" />
</div>

<perch:showall />
<?php include('../admin/runtime.php'); ?>
<?php PerchSystem::set_var('page', perch_page_url(array(
        'include-domain' => true,
    ), true)); ?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title><?php perch_pages_title(); ?></title>

<link id='snipcart-theme' type='text/css'
  href='https://app.snipcart.com/themes/base/snipcart.css' 
  rel='stylesheet' />




</head>
<body>
    <br />
    <div style="width:900px; margin:0 auto;">
        <div style="float:left; background-color:whitesmoke; padding:10px;">
            <div style="width:200px; float:left;">
                <p><strong>Sub Pages</strong></p>
                <?php 
                    perch_pages_navigation(array(
                        'from-path'            => '/snipcart',
                        'levels'               => 0,
                        'hide-extensions'      => false,
                        'hide-default-doc'     => true,
                        'flat'                 => false,
                        'template'             => 'item.html',
                        'include-parent'       => false,
                        'skip-template'        => false,
                        'siblings'             => false,
                        'only-expand-selected' => false,
                        'add-trailing-slash'   => false,
                        'navgroup'             => false,
                        'include-hidden'       => false,
                    ));
                ?>
            </div>
            <div style="width:550px; float:right; background-color: #fff; padding-left: 20px;">
                <div style="float:left;">
                    <h1><?php perch_pages_title(); ?></h1>



                    <?php perch_content('Details'); ?>
                </div>
            </div>
        </div>
    </div>

    <script 
  src='//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js'  
  type='text/javascript'></script>

<script type='text/javascript' 
  id='snipcart' 
  data-api-key='OGU5ODljYmItZDYxYy00ZmI3LThiZmMtZmQ4MDk3NDIzYzEx' 
  src='https://app.snipcart.com/scripts/snipcart.js'></script>



</body>
</html>
Drew McLellan

Drew McLellan 2638 points
Perch Support

I see no reason why that shouldn't work. What does this output?

<?php
    perch_page_url(array(
        'include-domain' => true,
    ));
?>

It spits out this which is correct.

https://perch.uisandbox.es/snipcart/brandon.php

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, progress! How about this:

<?php
    $out = perch_page_url(array(
        'include-domain' => true,
    ), true);
    echo $out;
?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, great. I wonder if the 'page' variable name is being trampled over somewhere (PHP is bad for this).

Give this a go:

PerchSystem::set_var('full_page_url', perch_page_url(array(
        'include-domain' => true,
    ), true));

and then in your template

<perch:content id="full_page_url" type="text" />

Nope you can view the page and see that "full_page_url" is empty.

https://perch.uisandbox.es/snipcart/brandon.php

Drew McLellan

Drew McLellan 2638 points
Perch Support

Is this this region you're using?

perch_content('Details');

if so:

perch_content_custom('Details', array());

Okay I added it to that page.

https://perch.uisandbox.es/snipcart/brandon.php

Drew McLellan

Drew McLellan 2638 points
Perch Support

And the perch_content_custom() change?

yes

<?php include('../admin/runtime.php'); ?>
<?php PerchSystem::set_var('full_page_url', perch_page_url(array(
        'include-domain' => true,
    ), true));
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title><?php perch_pages_title(); ?></title>

<link id='snipcart-theme' type='text/css'
  href='https://app.snipcart.com/themes/base/snipcart.css' 
  rel='stylesheet' />




</head>
<body>
    <br />
    <div style="width:900px; margin:0 auto;">
        <div style="float:left; background-color:whitesmoke; padding:10px;">
            <div style="width:200px; float:left;">
                <p><strong>Sub Pages</strong></p>
                <?php 
                    perch_pages_navigation(array(
                        'from-path'            => '/snipcart',
                        'levels'               => 0,
                        'hide-extensions'      => false,
                        'hide-default-doc'     => true,
                        'flat'                 => false,
                        'template'             => 'item.html',
                        'include-parent'       => false,
                        'skip-template'        => false,
                        'siblings'             => false,
                        'only-expand-selected' => false,
                        'add-trailing-slash'   => false,
                        'navgroup'             => false,
                        'include-hidden'       => false,
                    ));
                ?>
            </div>
            <div style="width:550px; float:right; background-color: #fff; padding-left: 20px;">
                <div style="float:left;">
                    <h1><?php perch_pages_title(); ?></h1>



                    <?php perch_content_custom('Details', array()); ?>
                </div>
            </div>
        </div>
    </div>

    <script 
  src='//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js'  
  type='text/javascript'></script>

<script type='text/javascript' 
  id='snipcart' 
  data-api-key='OGU5ODljYmItZDYxYy00ZmI3LThiZmMtZmQ4MDk3NDIzYzEx' 
  src='https://app.snipcart.com/scripts/snipcart.js'></script>



</body>
</html>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Puzzling. Can you try rearranging:

<?php 
    PerchSystem::set_var('full_page_url', perch_page_url(array(
        'include-domain' => true,
    ), true));
    perch_content_custom('Details', array()); 
?>