在博客帖子中使用变量

问题描述 投票:7回答:2

我正在使用博主制作播客。它工作得很好,但我发现自己复制/粘贴很多东西,当两个或三个变量和一个模板能很好地完成工作时。

大多数帖子看起来像这样:

É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>

三件事改变的地方:

  • 顶部的文字(示例中的“É​​tudedeExode 6.14-7.13。”)
  • 声音文件的链接(实际上是data:post.link,但我似乎无法在那里使用expr:src
  • 传递给biblia:bible标签的参考文献(这里是'Ex6.14-7.13')

有没有办法可以为我的博客文章使用模板和变量,而不是每次都手动复制和更改内容?

templates blogger
2个回答
1
投票

我个人并不熟悉博客,但看起来你可以创建一个小部件,并以这种方式分配变量:

<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>

然后使用它......

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

这是一个彻头彻尾的垃圾拍摄,虽然我从来没有亲自使用博客,这只是来自文档。

我在这里引用材料:

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


1
投票

但是,您可以将字符串对象转换为有效的Blogger XML数据。因此,首先,您需要将此对象编写为帖子内容(确保您处于HTML模式):

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

之后,在您的博客模板中,找到<data:post.body/>然后替换为:

<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>

这是基本概念:https://www.dte.web.id/2018/07/custom-blogger-widget.html

© www.soinside.com 2019 - 2024. All rights reserved.