Using variables in blogger posts
Asked Answered
P

2

7

I'm using blogger to make a podcast. It works really well, but I find myself copy/pasting a lot of things, when two or three variables and a template would do the job really well.

Most of the posts look like this:

Étude de Exode 6.14-7.13.
<br />
<audio controls>
  <source src="file.mp3" type="audio/mpeg">
  <embed height="50" width="100" src="file.mp3">
</audio>

<biblia:bible layout="minimal" resource="lsg" width="400" height="600" historyButtons="false" navigationBox="false" resourcePicker="false" shareButton="false" textSizeButton="false" startingReference="Ex6.14-7.13"></biblia:bible>

Where three things change:

  • the text on top ("Étude de Exode 6.14-7.13." in the example)
  • the link to the sound file (which is actually data:post.link, but I can't seem to be able to use expr:src there unfortunately)
  • the references passed to the biblia:bible tag (here 'Ex6.14-7.13')

Is there a way I could use a template and variables for my blog posts instead of copying and changing things manually every time?

Pintsize answered 21/8, 2015 at 20:41 Comment(2)
What kind of interface would you like for such template editing ? You are certainly aware of the existence of the blogger APIShack
I'd like to avoid maintaining an external system using the API. Instead, I was wondering if variables could be declared/used in post templates, like they can be in the blog template and widgets.Pintsize
B
4

You can, however, convert a string object into valid Blogger XML data. So, first, you need to write this object as your post content (make sure you are in the HTML mode):

{
  text: "Étude de Exode 6.14-7.13.",
  source: "file.mp3",
  ref: "Ex6.14-7.13"
}

After that, inside your blog template, find <data:post.body/> then replace with this:

<b:with var='param' expr:value='data:post.body'>
  <data:param.text/>
  <br/>
  <audio controls='controls'>
    <source expr:src='data:param.source' type='audio/mpeg'/>
    <embed height='50' width='100' expr:src='data:param.source'/>
  </audio>
  <biblia:bible layout='minimal' resource='lsg' width='400' height='600' historyButtons='false' navigationBox='false' resourcePicker='false' shareButton='false' textSizeButton='false' expr:startingReference='data:param.ref'/>
</b:with>

Here’s the basic concept: https://www.dte.web.id/2018/07/custom-blogger-widget.html

Boride answered 5/9, 2018 at 16:17 Comment(0)
P
1

I am not personally familiar with blogger, but it looks like you can create a widget, and assign variables that way:

<html
 xmlns  = 'http://www.w3.org/1999/xhtml' 
 xmlns:b  = 'http://www.google.com/2005/gml/b' 
 xmlns:data = 'http://www.google.com/2005/gml/data' 
 xmlns:expr = 'http://www.google.com/2005/gml/expr' 
>

<b:includable id='post' var='post'>

<data:post.title/>
<br />
<audio controls>
  <source src="<data:post.file/>" type="audio/mpeg">
  <embed height="50" width="100" src="<data:post.file/>">
</audio>

<biblia:bible layout="minimal" resource="lsg" width="400" height="600" historyButtons="false" navigationBox="false" resourcePicker="false" shareButton="false" textSizeButton="false" startingReference="<data:post.reference/>"></biblia:bible>

</b:includable>

and then to use it...

<b:include name='post' data='p' cond='index < 10'/>

This is a total crap shoot though as I have never used blogger personally, this is just from documentation.

I am referencing material from here:

https://support.google.com/blogger/answer/46995?hl=en

http://thoughtsomething.blogspot.com/2009/01/understanding-blogger-template-1.html

http://helplogger.blogspot.com/2014/03/how-to-create-custom-color-and-font-variable-definitions-to-blogger.html

Pondweed answered 1/9, 2015 at 15:5 Comment(1)
It looks ok, but I couldn't get it to work at all. I'll have to try harder. Widgets apparently can't be used inside posts from what I can tell.Pintsize

© 2022 - 2024 — McMap. All rights reserved.