XF 2.1 AMP thread version by yourself. Possible?

Anatoliy

Well-known member
So, as there is no room for hope any more that AMP will be in xF 2.2, I'd like to investigate possibilities to build it by myself. As I'm not a developer and doesn't know the xF system well, I need some assassinate. I have few questions and would be very thankful for any help & advice.

<link rel="amphtml" href="AMP URL"> tag
Is it possible to insert those tags in certain threads pointing to their amp versions? I'm thinking of using custom tread fields. I have no idea what's that, but I guess I can create a custom field where I can put amp urls. And then in a template put something like "<if:xf that custom field is not empty>$ampUrl</if:xf>
Is it doable or I'm just fantasizing?
 
Solution
<xf:if is="$thread.custom_fields.amp">
<xf:head option="something"><link rel="amphtml" href="{{$thread.custom_fields.amp}}"></xf:head>
</xf:if>

not sure what option is used for exactly.

here's an example of usage

<xf:head option="rss_forum"><link rel="alternate" type="application/rss+xml" title="{{ phrase('rss_feed_for_x', {'title': $forum.title})|for_attr }}" href="{{ link('forums/index.rss', $forum) }}" /></xf:head>

edit: oh use {{ }} instead of { } for the variable
That's only for XF1. I have not released an XF2 version.
yeah, I had such a feeling )

Anyway, I looked into that custom thread thing. Not exactly what I expected but still it looks doable.
I created a custom field , made it editable by admin only. Now I guess I need somewhere in post(?) template ad conditionals to hide it from everyone but admin. And then in some (page_container?) template add in head conditional to show link to amp version if custom field is not empty. Would you guide what templates do I need and what would be the conditional code?
 
ok. found in post_macros this code

Code:
                            <xf:if is="$post.isFirstPost()">
                                <xf:macro template="custom_fields_macros" name="custom_fields_view"
                                    arg-type="threads"
                                    arg-group="before"
                                    arg-onlyInclude="{$thread.Forum.field_cache}"
                                    arg-set="{$thread.custom_fields}"
                                    arg-wrapperClass="message-fields message-fields--before" />
                            </xf:if>

I'm going to add the conditional to hide custom field data from everyone except admin:

Code:
                            <xf:if is="$post.isFirstPost()">
                                <xf:macro template="custom_fields_macros" name="custom_fields_view"
                                    arg-type="threads"
                                    arg-group="before"
                                    arg-onlyInclude="{$thread.Forum.field_cache}"
                                    <xf:if is="$xf.visitor.is_admin">
                                    arg-set="{$thread.custom_fields}"
                                     </xf:if>
                                    arg-wrapperClass="message-fields message-fields--before" />
                            </xf:if>


Could you please confirm that my forum will not explode because of that code change? )
 
Hmm. So yeah adding the alt amp tag in there is enough to tell google to go to that other page for amp.

But then you have to somehow host the other page. What’s your plan on that?
 
Hmm. So yeah adding the alt amp tag in there is enough to tell google to go to that other page for amp.

But then you have to somehow host the other page. What’s your plan on that?
I didn't think about it yet, I prefer "step by step" tactic, and now I need to find the way how to insert that custom field data into page head. Then I'll create 10-100 test amp pages in /amp/ folder and will watch google analytics. Maybe will install wordpress for easy creations of hundreds amp pages... I know it looks silly, but still it's a chance to get amp pages. What other option do I have? To wait for 10 years when xF will implement it?
 
so.. I was gonna suggest making an amp style and then somehow seeing if u could find a way to force a style on specific urls... but then I realized I don't think making an amp style in Xenforo is even possible.

It uses specific tags like <amp-img amongst others... and no inline-styles, no external css, no javascript. I just don't know if all those things are style-fixable by template alone.
 
It uses specific tags like <amp-img amongst others... and no inline-styles, no external css, no javascript. I just don't know if all those things are style-fixable by template alone.
and pix must have dimensions. xF would have to complitely rebuild their attachments system. and it would require way more room for storage... that's probably it doesn't have amps.

I see only way to build(by hands or with wp for example) amp threads versions separately from xF engine.

Are you good with conditionals? what would be the code for if custom thread field is not empty?
 
Well, i found this code in the other thread
<xf:if is="$thread.custom_fields.amp">{$thread.custom_fields.amp}</xf:if> that I put after <head> in the PAGE_CONTAINER template. It outputs custom field data, however not in the head section but in the body.
Can anyone please advice what's going on and how to fix it? Thanks in advance.

I'm one step away! Yahoo!!! 🕺
 
so I'm stuck...
this code in page_container
Code:
<xf:if is="$thread.custom_fields.amp">{$thread.custom_fields.amp}
<xf:else /><link rel="amphtml" href="#">
</xf:if>
outputs <link rel="amphtml" href="#"> for a thread with custom thread field not empty.

incorrect code? or $thread.custom_fields.amp doesn't exist on page_container level and this code can't be used here?
could anyone advice please?

hello hello hello
is there anybody out there? (c)
 
Try
<xf:if is="$thread.custom_fields.amp">
<xf:head><link rel="amphtml" href="{$thread.custom_fields.amp}"></xf:head>
</xf:if>

in thread_view
 
<xf:if is="$thread.custom_fields.amp">
<xf:head option="something"><link rel="amphtml" href="{{$thread.custom_fields.amp}}"></xf:head>
</xf:if>

not sure what option is used for exactly.

here's an example of usage

<xf:head option="rss_forum"><link rel="alternate" type="application/rss+xml" title="{{ phrase('rss_feed_for_x', {'title': $forum.title})|for_attr }}" href="{{ link('forums/index.rss', $forum) }}" /></xf:head>

edit: oh use {{ }} instead of { } for the variable
 
Solution
The solution background colour reminds me of the good old days of Yahoo!Answers

yahoo_answers.png
 
Top Bottom