深層インクルードとは

深層インクルードとは?

A.私の造語です

簡単に言えばインクルードの初期値を決める構文です。一番表にあるインクルード構文が簡単になる代わりにインクルード元が2つ必要になるというデメリットがあります。

例えばこんなインクルード元を作ったとしましょう。

URL: http://******.wikidot.com/sample-include


**{$sentence}**

code:1

このページをsampledisplayというページでインクルードした時、引数sentenceに何も入れなければ、インクルード先で表示されるのは

URL: http://******.wikidot.com/sampledisplay


{$sentence}

表示結果

となります。

ここで、インクルード文の引数に何も値を入れていない時は"undefined"と表示される様にしましょう。
この場合、sampledisplayから直接sample-includeをインクルードするのではなく、途中で別のページを噛ませます。今回は"sample-hubinclude"というページを噛ませたとしましょう。この時"sample-hubinclude"のページの構文は以下のようになります。

URL: http://******.wikidot.com/sample-hubinclude


[[include sample-include
|sentence = {$sentence}
|sentence = undefined
]]

code:2


ここで注目したいのはこのページがただsample-includeをインクルードしているだけのページである事、加えてsentenceという引数を2回定義している事です。
2回目に現れるsentenceは定数ですね。ではsampledisplayでsample-includeではなくsample-hubincludeを引数の設定なしで読み込むとどうなるでしょうか?

URL: http://******.wikidot.com/sampledisplay


[[include sample-hubinclude]]

code:3


するとcode:3ではsampledisplayにundefinedと表示されます。

URL: http://******.wikidot.com/sampledisplay


undefined

code:4

なぜそうなるのか

これはあくまでも予想ですが、インクルード文内に{$sentence}の様な引数を受ける文章がそのままあった場合、その値は自身の内部にある同名の引数と同じ値になる為と考えられます。
つまり、復習ですが、"sample-hubinclude"を引数なしで呼んだ場合下記の太字部分

[[include sample-include
|sentence = {$sentence}
|sentence = undefined
]]

ここはやはり{$sentence}という文字列のまま呼び出されます。
この時、この{$sentence}という変数は下記赤文字部分の値を取得するのだと考えられます。

[[include sample-include
|sentence = {$sentence}
|sentence = undefined
]]

つまり、普通のプログラムから考えれば逆なのですが、wikidotにおけるinclude文の変数(もしくは引数)は下から取得が行われていると考えればいいでしょう。流れとしては下記のものになると思います。

[[include sample-include
|sentence = {$sentence}
|sentence = undefined
]]
赤字のsentenceという引数の中にundefinedが格納される

[[include sample-include
|sentence = undefined
|sentence = undefined
]]
上部にある{$sentence}が赤字で記したsentenceの中身を取得し、undefinedになる。
その後再び引数sentenceに格納される


引数が定められている場合は恐らく下記の流れです。sample-hubincludeの引数(sentence)に"HelloWorld"と入れた場合を想定しています。

[[include sample-include
|sentence = HelloWorld
|sentence = undefined
]]
sentenceという引数の中にundefinedが格納される

[[include sample-include
|sentence = HelloWorld
|sentence = undefined
]]
sentenceという引数の中身がHelloWorldに上書きされる

この流れはあくまでも推測ですが、この様な機能がある為、インクルード元を呼び出す際、もう1つ別の、そのインクルード元をインクルードするだけのページを噛ませると、初期値を設定する事ができるのでしょう。

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License