<![CDATA[ Fetching custom TV on AMP pages. - My Forums]]> https://forums.modx.com/thread/?thread=103793 <![CDATA[Fetching custom TV on AMP pages.]]> https://forums.modx.com/thread/103793/fetching-custom-tv-on-amp-pages#dis-post-558254
'content' => $resource->get('content')

The problem is, this content is meant for full desktop pages and can't get validated, so I need custom AMP friendly content retreived instead of raw "content". I've created a TV named "amp-content" and I try to get it on AMP pages instead of content. Here is the current code in AMP Template:

Template code:
<h1>[[+amp_ptitle]]</h1>
    <amp-img src="[[+amp_image]]" alt="[[+amp_ptitle]]" width="[[+amp_image_width]]" height="[[+amp_image_height]]" layout="responsive"></amp-img>
    <article>[[+amp_content]]</article>


Snippet:
$modx->setPlaceholders(array(
        'ptitle' => $resource->get('pagetitle'),
        'pdescription' => $resource->get('description'),
        'content' => $resource->get('content'),
        'canonical' => $modx->makeUrl($resource->get('id'),'','','full'),
        'published' => $resource->get('publishedon'),
        'edited' => $resource->get('editedon'),
        'image' => $image_url,
        'image_width' => $width,
        'image_height' => $height
    ),'amp_');


So I'm trying to do something with this line:
'content' => $resource->get('content'),

What I want to do is: if there is amp-content TV available - fetch it, if not - get normal content.
Obviously, options like this don't work
'content' => $resource->get('amp-content'),

Also, I've tried
'content' => $tvr->get('amp-content'),

No luck.
So, is it possible to do something here, I'm new so this might be a noob question, thank you very much]]>
danilpro Apr 27, 2018, 06:05 AM https://forums.modx.com/thread/103793/fetching-custom-tv-on-amp-pages#dis-post-558254
<![CDATA[Re: Fetching custom TV on AMP pages.]]> https://forums.modx.com/thread/103793/fetching-custom-tv-on-amp-pages#dis-post-558279 Quote from: BobRay at Apr 28, 2018, 07:28 PM
I think this would do it:


Thank you, BobRay, it works!]]>
danilpro Apr 29, 2018, 06:32 AM https://forums.modx.com/thread/103793/fetching-custom-tv-on-amp-pages#dis-post-558279
<![CDATA[Re: Fetching custom TV on AMP pages. (Best Answer)]]> https://forums.modx.com/thread/103793/fetching-custom-tv-on-amp-pages#dis-post-558276
$tvValue = $resource->getTVValue('amp-content');
$docContent = empty($tvValue)? $resource->get('content') : $tvValue;
$modx->setPlaceholders(array(
        'ptitle' => $resource->get('pagetitle'),
        'pdescription' => $resource->get('description'),
 
        'content' => $docContent,

        'canonical' => $modx->makeUrl($resource->get('id'),'','','full'),
        'published' => $resource->get('publishedon'),
        'edited' => $resource->get('editedon'),
        'image' => $image_url,
        'image_width' => $width,
        'image_height' => $height
    ),'amp_');


You could do it with a little less code like this if you change the ptitle and pdescription placeholders to pagetitle and description:

$fields = $resource->toArray();
$tvValue = $resource->getTVValue('amp-content');
$fields['content'] = !empty($tvValue)? $tvValue : $fields['content'];
$fields = $array_merge($fields, array(
    'canonical' => $modx->makeUrl($resource->get('id'),'','','full'),
    'image' => $image_url,
    'image_width' => $width,
    'image_height' => $height,
));
$modx->setPlaceholders($fields, 'amp_');



]]>
BobRay Apr 28, 2018, 07:28 PM https://forums.modx.com/thread/103793/fetching-custom-tv-on-amp-pages#dis-post-558276
<![CDATA[Re: Fetching custom TV on AMP pages.]]> https://forums.modx.com/thread/103793/fetching-custom-tv-on-amp-pages#dis-post-558271 That's pretty much all I need. Thank you!

$modx->setPlaceholders(array(
        'ptitle' => $resource->get('pagetitle'),
        'pdescription' => $resource->get('description'),


        'content' => $resource->get('content'),
        'content' => $resource->getTVValue('amp-content'),


        'canonical' => $modx->makeUrl($resource->get('id'),'','','full'),
        'published' => $resource->get('publishedon'),
        'edited' => $resource->get('editedon'),
        'image' => $image_url,
        'image_width' => $width,
        'image_height' => $height
    ),'amp_');
]]>
danilpro Apr 28, 2018, 05:58 AM https://forums.modx.com/thread/103793/fetching-custom-tv-on-amp-pages#dis-post-558271
<![CDATA[Re: Fetching custom TV on AMP pages.]]> https://forums.modx.com/thread/103793/fetching-custom-tv-on-amp-pages#dis-post-558264
'content' => $resource->getTVValue('amp-content'),
]]>
Jako Apr 27, 2018, 04:29 PM https://forums.modx.com/thread/103793/fetching-custom-tv-on-amp-pages#dis-post-558264
<![CDATA[Re: Fetching custom TV on AMP pages.]]> https://forums.modx.com/thread/103793/fetching-custom-tv-on-amp-pages#dis-post-558261 We already have AMP working, that's not the issue. I just need to convert the resource content into amp friendly content, that's it]]> danilpro Apr 27, 2018, 12:42 PM https://forums.modx.com/thread/103793/fetching-custom-tv-on-amp-pages#dis-post-558261 <![CDATA[Re: Fetching custom TV on AMP pages.]]> https://forums.modx.com/thread/103793/fetching-custom-tv-on-amp-pages#dis-post-558259 Jako Apr 27, 2018, 11:54 AM https://forums.modx.com/thread/103793/fetching-custom-tv-on-amp-pages#dis-post-558259 <![CDATA[Re: Fetching custom TV on AMP pages.]]> https://forums.modx.com/thread/103793/fetching-custom-tv-on-amp-pages#dis-post-558257 Quote from: lkfranklin at Apr 27, 2018, 06:43 AM
How are you serving amp pages currently is it via the amp pages extra, switch template extra or another way? In the first two extras you're serving a different template anyway for amp pages so you could just replace the tvs with some amp specific created ones.
Like this:

The amp urls structure looks like this:
site.com/amp.html&page=page-slug]]>
danilpro Apr 27, 2018, 07:12 AM https://forums.modx.com/thread/103793/fetching-custom-tv-on-amp-pages#dis-post-558257
<![CDATA[Re: Fetching custom TV on AMP pages.]]> https://forums.modx.com/thread/103793/fetching-custom-tv-on-amp-pages#dis-post-558256 lkfranklin Apr 27, 2018, 06:43 AM https://forums.modx.com/thread/103793/fetching-custom-tv-on-amp-pages#dis-post-558256