amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

Support dynamic content for amp-carousel

Open sebastianbenz opened this issue 10 years ago • 28 comments

amp-carousel currently does not support dynamic content, e.g. varying the number of slides for different viewers. This limits the possibilities of personalizing the content of a carousel.

Originally, I planned to use amp-list for this and I was surprised to learn that it doesn't work with amp-carousel (then I realized there is a reason why it's called amp-list). I was trying something like:

<amp-carousel>
   <amp-list>
      <template>
         <amp-img></..>
      </template>
   </amp-list>
</amp-carousel>

//cc @ericlindley-g @rudygalfi

sebastianbenz avatar Aug 06 '16 07:08 sebastianbenz

@sriramkrish85 @dvoytenko — is this possible, or would we need to build another mechanism to populate amp-carousel with content returned from an additional server call?

ericlindley-g avatar Aug 06 '16 17:08 ericlindley-g

carousel expects each of its child to be one slide. So we might have to do some extra building on runtime to accomodate this and also update the carousel in runtime (ie keep rebuilding for each new response and stay at the right slide.) This is hard but not impossible. I think we could build a poll for new slides feature rather than accommodating amp-list and have the poll url passed in as conf! - all these are just my ideas.

camelburrito avatar Aug 06 '16 18:08 camelburrito

Nice — and just to clarify, I think the intent would only be for one call on load, to populate personalized results (by locale, by CID, by some other parameter or combination of parameters collected by the server), and not multiple polls, like amp-live-list

ericlindley-g avatar Aug 06 '16 18:08 ericlindley-g

@sebastianbenz @ericlindley-g For background. So far, we've generally been cautious with something like this to avoid a situation where people start to simply use AMP as a rendering engine. amp-list has a number of restrictions to ensure that this is not the case. We believe that where the main content is concerned, server-side rendering is for the primary performance benefit and improves embed-ability.

dvoytenko avatar Aug 08 '16 16:08 dvoytenko

@sebastianbenz @ericlindley-g @dvoytenko dvoytenko SO is this a dead end and wont be implemented in the future. ie a Carousel that can call up images from a JSOn COR file.. Because I would like to reference you to this page -- https://github.com/disqus/amphtml/blob/master/spec/amp-html-templates.md under usage it does say "" The use of the template is up to a specific AMP element that wants to use it. An AMP element would typically look for a template within its children or using a template's ID. For instance, an amp-carousel element may (in the future) use a CORS endpoint and an AMP template to load and render a dynamic set of slides. "" SO at some point some one had a vision A very useful vision.. Now its mentioned that the reason it isnt implimented is to prevent people using it as a rendering engine. Is that being to guarded.. Taking away functionality because it me be useful.. ? Just a frustrated interpretation. But all systems will be abused and manipulated, im sure but hopefully the greater good can prevail. American elections included..

escoffierdesign avatar Nov 10 '16 12:11 escoffierdesign

sounds good to me @dvoytenko.

escoffierdesign avatar Nov 14 '16 18:11 escoffierdesign

Thanks everyone for the input! LGTM the use case and the format that @sebastianbenz suggests.

/to @ericlindley-g and @rudygalfi to schedule the work.

dvoytenko avatar Dec 01 '16 19:12 dvoytenko

My use case for this is related content / latest articles links. 95% of our page updates are becasue some related content link changed. We can most some of that into amp-list but we've held off becasue we'd like to be able to use the nice amp carousel UX. What's the latest on the schedule?

jpettitt avatar Dec 12 '16 21:12 jpettitt

I also need to use amp-carousel with pulling data from amp-list.

It seems amp-list works with amp-selector. https://github.com/ampproject/amphtml/issues/9536#issuecomment-304064722

So, no implementation for amp-carousel?

oimos avatar Jun 01 '17 01:06 oimos

Thanks for the feedback — this is something we've started thinking about in earnest again (presented in a recent design review), and makes sense in a range of use cases. (am bumping the priority up a bit for the GitHub label)

ericlindley-g avatar Jun 01 '17 01:06 ericlindley-g

FYI to folks waiting on this issue: while AMP doesn't yet support amp-list nested inside of amp-carousel, it does support amp-carousel nested inside of amp-list, so that may be a workaround for you in the time being. Thanks for your patience!

ericlindley-g avatar Jun 23 '17 20:06 ericlindley-g

Pardon my ignorance, but how do you use amp-carousel nested inside amp-list for that? Wouldn't it create multiple separate amp-carousels instead of a single one? Thanks in advance!

SmokinClove avatar Jul 10 '17 03:07 SmokinClove

Good question, @SmokinClove — there's some flexibility here. The difference between creating multiple amp-carousels and a single amp-carousel is in the data that your server returns as a response to amp-list.

That is, you could use amp-list to create multiple separate amp-carousels by including several objects in the items array, but you could also just return the data to create a single instance of an amp-carousel by having just a single object in the items array.

Note that using items is the default, but is optional, you can see https://www.ampproject.org/docs/reference/components/amp-list and https://ampbyexample.com/components/amp-list/ for more details

ericlindley-g avatar Jul 10 '17 17:07 ericlindley-g

I tried to use amp-carousel inside of amp-list with the structure of below. However, I see multiple amp-carousel elements are generated instead of showing multiple images inside of a single amp-carousel. Does anybody knows how to work around for this?

#JSONURL
{
	"items": [
		{
			"text": [
				"SAMPLE TEXT"
			],
			"image": [
				{
					"value": "IMAGE URL",
					"url": "IMAGE LINK",
					"alt": "IMG ALT"
				}
			]
		},
		{
			"text": [
				"SAMPLE TEXT"
			],
			"image": [
				{
					"value": "IMAGE URL",
					"url": "IMAGE LINK",
					"alt": "IMG ALT"
				}
			]
		}
	]
}


<amp-list width="auto" height="400" layout="fixed-height" src="JSONURL">
     <template type="amp-mustache">
       <amp-carousel height="200" layout="fixed-height" type="carousel">
       {{#image}}
         <a href="{{url}}">
           <amp-img src="{{value}}" layout="fixed" width="100" height="100" alt="{{alt}}"></amp-img>
         </a>
       {{/image}}
       </amp-carousel>
     </template>
</amp-list>

oimos avatar Jul 26 '17 10:07 oimos

Thanks for reaching out @stoneshower — @aghassemi, do you want to share that demo you built? I believe you had this working, but thinking through this again I want to double-check that you had this working for instances where the client didn't know how many items were in the carousel until getting the JSON response.

ericlindley-g avatar Jul 26 '17 14:07 ericlindley-g

can't find my demo, @stoneshower all you need to do is to have a single entry in items e.g.

{"items": [{
    "values": [/*...*/]

then you iterate the values array using template syntax, e.g.

<amp-list width="auto" height="400" layout="fixed-height" src="JSONURL">
     <template type="amp-mustache">
       <amp-carousel height="200" layout="fixed-height" type="carousel">
       {{#values}}
         {{#image}}
         <a href="{{url}}">
           <amp-img src="{{value}}" layout="fixed" width="100" height="100" alt="{{alt}}"></amp-img>
         </a>
         {{/image}}
       {{/values}}
       </amp-carousel>
     </template>
</amp-list>

aghassemi avatar Jul 26 '17 22:07 aghassemi

Thank you @ericlindley-g and @aghassemi ! Actually I need to use the data structure of the "items" so I cannot change it for now. I think I need to wait for the implementation of amp-list nested in amp-carousel.

oimos avatar Jul 26 '17 23:07 oimos

Not sure if it'd help, but the location of an array of items can be customized somewhat using the items attribute: https://github.com/ampproject/amphtml/blob/master/extensions/amp-list/amp-list.md#items-optional

dvoytenko avatar Jul 26 '17 23:07 dvoytenko

@dvoytenko Thank you for the link! I'm gonna take a look at it.

oimos avatar Jul 27 '17 00:07 oimos

This issue hasn't been updated in awhile. @ericlindley-g Do you have any updates?

ampprojectbot avatar Oct 30 '17 21:10 ampprojectbot