Forum

Thread tagged as: Question

Share a template

I am trying to share an article (based on a template) on Facebook. How can I add the id to the page path? The id is:

id="article_<perch:content id="perch_item_index" type="hidden" />"

The link to the page is:

<a href="https://www.facebook.com/sharer/sharer.php?u=https://www.domain.com<?php echo PerchSystem::get_page(); ?>">Share on FB</a>

Thanks a lot!

Martin Stettler

Martin Stettler 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

perch_item_index won't give you a unique ID. Use _id instead.

First I should add the page id too, then the template id. I tried this, but it doesn't work:

<a href="https://www.facebook.com/sharer/sharer.php?u=https://www.domain.com<?php echo PerchSystem::get_pagePath().php get_id(); ?>">Share on FB</a>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Where did that code come from?

Maybe my approach is wrong. I wanted to reuse the code I have for sharing a page (see my first thread). But in that case the page and the article both are templates. Maybe there is a better way to share an article from a perch template?

Drew McLellan

Drew McLellan 2638 points
Perch Support

What end result are you trying to get to?

I want to share articles on Facebook. The articles are based on a Perch template as well the page.

Drew McLellan

Drew McLellan 2638 points
Perch Support

What HTML are you trying to output? Please give an example so that I know what you're trying to do.

Here is an example of a path to an article: https://www.domain.com/news/news1.php#news_1

The page and the article are Perch templates.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, great. What information do we have in the environment to locate the article?

This is the container of the article:

<div id="news_<perch:content id="perch_item_index" type="hidden" />">
...
</div>
Drew McLellan

Drew McLellan 2638 points
Perch Support

You could do something like:

https://www.domain.com/news/news1.php#news_<perch:content id="_id" type="hidden" />

This is fine to get to the right article. But as the page name is also from a template I need to add this too. <perch:pages id="pageNavText"/> does not output it, it's empty before «.php».

https://www.domain.com/news/<perch:pages id="pageNavText"/>.php#news_<perch:content id="_id" type="hidden" />
Drew McLellan

Drew McLellan 2638 points
Perch Support

perch:pages tags will only work in a navigation template - not a content or blog template.

I was trying to use: perch_pages_navigation_text() but it's wrong, too. How should I do it? Thanks for your help!

Drew McLellan

Drew McLellan 2638 points
Perch Support

I'm confused. Are you doing this in a template or in the page? Do you know the page path, or do you need to figure it out? There's so much confusing information and guesswork here that I'm not clear on what we're actually trying to achieve. I don't think it's anything complex!

Sorry, I try to clear this: the articles I'd like to share on Facebook finally are a template. That's what we have figured out already: <perch:content id="_id" type="hidden" />. The second thing is, I need to get the page name. (The articles are in a template page.) So the question is how I get the «pageName» in the path?

https://www.domain.com/news/pageName.php#news_<perch:content id="_id" type="hidden" />

I agree with you, it couldn't be difficult... Your help is much appreciated!

Drew McLellan

Drew McLellan 2638 points
Perch Support

The page name or the path?

The page name!

Drew McLellan

Drew McLellan 2638 points
Perch Support

I had this before, but all formats I tried were wrong. How is it correct, please?

https://www.domain.com/news/<?php perch_pages_title(); ?>.php