• Resolved yuranikolaev

    (@yuranikolaev)


    Hey there!

    I’m trying to make latest comments list with amp-list. Here is my code

    
    <amp-list 
    
    	layout="fixed-height"
    	width="auto"
    	height="100vh"
    	items="."
    	src="/wp-json/wp/v2/comments?per_page=50"
     	load-more="auto"
     	id="live-comments-list"
    >
    	<template type="amp-mustache">
    		
    		<div class="sidebar-live-comments__wrapper">
    			<div class="sidebar-live-comments__body">
    				<?php $comment = '{{#content}}<code>rendered</code>{{/content}}'; 
    					  $authorID = '{{author}}'; 
    				?>
    
    				<i class="fas fa-user"></i> 
    				<span class="sidebar-live-comments__author">{{author_name}}</span>
    				
    				<div class="sidebar-live-comments__content"><?php echo $comment; ?></div>
    				<a class="sidebar-live-comments__link" href="{{link}}">Reply</a>
    			</div>
    		</div>
    		
    	</template>
    
    	 <div placeholder>
    	 	<div class="sidebar-live-comments__placeholder-item"></div>
    	 </div>
    
    	<div fallback>Failed to load data.</div>
    
    </amp-list>
    

    As making custom REST API endpoint is a little bit tricky, I just want to use wordpress core functions such as get_permalink(), get_the_author_url(), etc. with amp-mustache template tags (for ex: $id = '{{id}}'; get_permalink($id); )

    But for some reason wp functions doesn’t work
    (also no luck with intval() and strval() and google search ?? )
    Is there any way to make it work?

    Thanks

    • This topic was modified 4 years, 11 months ago by yuranikolaev.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Weston Ruter

    (@westonruter)

    I’m confused why you are needing to use PHP functions in the Mustache template. All of the data being rendered should be coming from the REST API response, no?

    Plugin Author Weston Ruter

    (@westonruter)

    This seems to be the markup you need:

    <amp-list
    	layout="fixed-height"
    	width="auto"
    	height="100vh"
    	items="."
    	src="/wp-json/wp/v2/comments?per_page=50&type=comment"
    	id="live-comments-list"
    >
    	<template type="amp-mustache">
    		<div class="sidebar-live-comments__wrapper">
    			<div class="sidebar-live-comments__body">
    				<i class="fas fa-user"></i>
    				<span class="sidebar-live-comments__author">{{author_name}}</span>
    
    				<div class="sidebar-live-comments__content">
    					<code>content.rendered</code>
    				</div>
    				<a class="sidebar-live-comments__link" href="{{link}}">Reply</a>
    			</div>
    		</div>
    	</template>
    
    	<div placeholder>
    		<div class="sidebar-live-comments__placeholder-item"></div>
    	</div>
    
    	<div fallback>Failed to load data.</div>
    
    </amp-list>
    • This reply was modified 4 years, 11 months ago by Weston Ruter.
    Thread Starter yuranikolaev

    (@yuranikolaev)

    Hey Weston, thanks for reply!

    I’m confused why you are needing to use PHP functions in the Mustache template. All of the data being rendered should be coming from the REST API response, no?

    Well, there are lot of reasons, but firstly — speed. It is way much faster to use <get_the_post_thumbnail($id)> instead of write a bunch of stuff with all thouse srcset, sizes etc.

    Now I know, AMP render mustache tags on client, so there is no way to use it in php template

    closed

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Using amp-mustache template tags inside wordpress functions’ is closed to new replies.