我有一个有两个页面(page1.html
和page2.html
)的jekyll网站,它们都使用相同的布局。此布局在给定的子目录中打印有关其他页面的一些信息。例如
{% for p in site.pages %}
{{ p.title }}
{% endfor %}
---
layout: test
---
this page lists the title of my books...
这将打印站点中每个页面的标题,但是我希望它仅打印子目录/books
中的页面标题,因此我将布局页面更改为
{% for p in site.pages | where: 'dir','/books/' %}
{{ p.title }}
{% endfor %}
这可以正常工作,但是我希望另一个页面使用相同的布局并列出我的漫画内容(位于/comics
文件夹中)而不是我的书,因此我将更改网站的结构通过以下方式:
{% for p in site.pages | where: 'dir','/{{ page.directory_to_scan }}/' %}
{{ p.title }}
{% endfor %}
---
layout: test
directory_to_scan: books
---
this page lists the title of my books...
---
layout: test
directory_to_scan: comics
---
this page lists the title of my comics...
但是,这不起作用,并且根本不打印标题。
答案 0 :(得分:1)
您不能混合标签和过滤器(assign
除外)。此外,无需将变量括在双括号中的filter
上:
---
directory_to_scan: '/comics/'
---
布局将使用:
{% assign my_pages = site.pages | where: 'dir', page.directory_to_scan %}
{% for p in my_pages %}
{{ p.title }}
{% endfor %}
答案 1 :(得分:0)
因此,我最终通过使用public class TipsHelper {
public static DocumentSnapshot getTips(String cat, int position) {
String documentTips = "TIPS" + position;
Log.e("TAG"," document call = "+documentTips);
return FirebaseFirestore.getInstance().collection("TIPS").document("SchoolTIPS").collection(cat).document(documentTips).get().getResult();
}
}
过滤器在循环之前组装了字符串来解决了问题。
2019-04-13 16:38:52.540 17276-17276/com.orla.mylife E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.orla.mylife, PID: 17276
java.lang.IllegalStateException: Task is not yet complete
at com.google.android.gms.common.internal.Preconditions.checkState(Unknown Source:29)
at com.google.android.gms.tasks.zzu.zzb(Unknown Source:121)
at com.google.android.gms.tasks.zzu.getResult(Unknown Source:12)
at com.orla.mylife.api.TipsHelper.getTips(TipsHelper.java:13)
at com.orla.mylife.school.tips.CategoryTipsActivity.OnClickThermoButton(CategoryTipsActivity.java:61)
at com.orla.mylife.school.tips.CategoryTipsActivity_ViewBinding$1.doClick(CategoryTipsActivity_ViewBinding.java:48)
at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:22)
at android.view.View.performClick(View.java:6291)
at android.view.View$PerformClick.run(View.java:24931)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:101)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7529)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
2019-04-13 16:38:52.552 17276-17276/com.orla.mylife I/Process: Sending signal. PID: 17276 SIG: 9