PyEmbed allows you to control how embeddings are rendered using Jinja2 templates. For example, if you want to include the thumbnail image when embedding a link, you could use a template like this:
<a href="{{content_url}}"><img src="{{thumbnail_url}}" /></a>
In order to use the Jinja2 renderer, you must create a directory containing template files for each type of OEmbed resource. These files must be named:
You can then create the renderer as follows:
>>> from pyembed.jinja2 import Jinja2Renderer
>>> renderer = Jinja2Renderer(path_to_template_dir)
For more information on how to use the renderer, see the introduction to customization.
The table below shows which parameters are available for each response type. For more information, see section 2.3.4 of the OEmbed spec.
The exception is the first parameter, content_url
, which contains the URL that was requested to be embedded.
Parameter | Link | Photo | Rich | Video |
---|---|---|---|---|
content_url | Required | Required | Required | Required |
type | Required | Required | Required | Required |
version | Required | Required | Required | Required |
title | Optional | Optional | Optional | Optional |
author_name | Optional | Optional | Optional | Optional |
author_url | Optional | Optional | Optional | Optional |
provider_name | Optional | Optional | Optional | Optional |
provider_url | Optional | Optional | Optional | Optional |
cache_age | Optional | Optional | Optional | Optional |
thumbnail_url | Optional | Optional | Optional | Optional |
thumbnail_width | Optional | Optional | Optional | Optional |
thumbnail_height | Optional | Optional | Optional | Optional |
url | Not present | Required | Not present | Not present |
width | Not present | Required | Required | Required |
height | Not present | Required | Required | Required |
html | Not present | Not present | Required | Required |