# 関連記事というモジュールを作成したい

**URL:** <https://community.hubspot.com/t/topic/105497>\
**Category:** CRM\
**Created:** [April 23, 2024, 6:19am UTC](https://community.hubspot.com/t/topic/105497 "2024-04-23T06:19:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MMatsunaga](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@MMatsunaga](https://community.hubspot.com/u/MMatsunaga)\
**Post date:** [April 23, 2024, 6:19am UTC](https://community.hubspot.com/t/topic/105497/1 "2024-04-23T06:19:42Z")

</div>

ブログ内のモジュールで「関連記事」というものを作成しました。  
リンクフィールドで、コンテンツ内のブログ記事を選択したらリンクが生成されるのですが、ここのLinkTextの部分を選択した記事のタイトルにしたいです。そこで、  
・自動でタイトルの持ってきてくれるHubL変数はありますでしょうか？  
・できればサムネイル画像も表示したいです。

 ![スクリーンショット 2024-04-09 14.18.26.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/a/f/afa0834de15c838d930f5a9d07aab450ad197cb8.png)

{{[content.name](http://content.name/)}}を挿入するだけでは駄目でしたので、ご享受いただけますと幸いです。お手数おかけしますが、よろしくお願いいたします。

```lia-code-sample
{% set href = module.link_field.url.href %}
{% if module.link_field.url.type is equalto "EMAIL_ADDRESS" %}
	{% set href = "mailto:" + href %}
{% endif %}
<a href="{{ href|escape_url }}"
	{% if module.link_field.open_in_new_tab %}target="_blank"{% endif %}
	{% if module.link_field.rel %}rel="{{ module.link_field.rel|escape_attr }}"{% endif %}
	>
	Link text //ここにタイトル名をだしたい
</a>

```

---

<div class="post-metadata">

**Author:** ![marykashima](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/marykashima/32/13515_2.png) [@marykashima](https://community.hubspot.com/u/marykashima)\
**Post date:** [April 24, 2024, 3:10am UTC](https://community.hubspot.com/t/topic/105497/2 "2024-04-24T03:10:51Z")

</div>

Moduleの近しい事例を共有します。

```lia-code-sample
{% if module.article|length > 0 %}
		<ul>
	{% for article in module.article %}
			{% set content = content_by_id(article.url_field.content_id) %}
			<li id="guideBlogPost{{ loop.index0 }}">
				<a href="{{ content.absolute_url }}">
					{% if content.featured_image %}
					<img src="{{ content.featured_image }}" alt="{{ content.name }}" />
					{% else if %}
					<img src="/hubfs/no_img.png" alt />
					{% endif %}
					<div class="title"><h3>{{ content.name }}</h3></div>
				</a>
			</li>
	{% endfor %}
		</ul>
{% endif %}

```

Module フィールドには Articleでグループ化して、複数ある場合はリストで表現するようにしています。

あとはグループ配下にあるURLフィールドで任意のコンテンツを呼び出すと、紐づいたabsolute\_url,featured\_image,name（これがタイトル）が呼び出されます。

 ![marykashima_0-1713927983380.png](https://d2qpr2jzcazej7.cloudfront.net/original/2X/8/859edf84ccd611c810e7c093622adcd43b9f348b.png)

参考になれば幸いです。
