「ver4/関数リファレンス/BcBaser js」の版間の差分
提供: baserCMS公式ガイド
Katokaisya (トーク | 投稿記録) |
Webbingstudio (トーク | 投稿記録) (CakePHPの仕様変更に伴い、関数の説明を大幅に変更) |
||
行1: | 行1: | ||
− | |||
− | |||
## 説明 | ## 説明 | ||
− | + | JavaScriptの読み込みタグを出力する。 | |
## 使い方 | ## 使い方 | ||
<syntaxhighlight lang="php"> | <syntaxhighlight lang="php"> | ||
− | $this->BcBaser->js( $url , [$inline] ); | + | <?php $this->BcBaser->js( $url , [$inline] ); ?> |
</syntaxhighlight> | </syntaxhighlight> | ||
## パラメータ | ## パラメータ | ||
− | + | (array)$url | |
− | : | + | : JavaScriptファイルまでのパス。拡張子は必要ない。キーを含まない値のみの配列として指定し、配列の順番の通りにJSが読み込まれる。 |
− | + | : 先頭にスラッシュをつけた場合は、baserCMSのルートからのパスとなる。スラッシュをつけず相対パスとした場合は、 /theme/{テーマ名}/js に該当ファイルが存在している場合、そのファイルへのパスとなる。 | |
(boolean)$inline | (boolean)$inline | ||
− | : | + | : 「true」を指定すると、関数を指定した箇所で一行ずつ改行して出力し、「false」を指定すると、管理画面用CSSの出力が終了してから改行を詰めて出力する。(初期値 : true) |
− | : | + | |
## 戻り値 | ## 戻り値 | ||
行25: | 行22: | ||
####コード | ####コード | ||
<syntaxhighlight lang="php"> | <syntaxhighlight lang="php"> | ||
− | <?php $this->BcBaser->js( ' | + | <?php $this->BcBaser->js(array( |
+ | 'jquery-3.3.1.min.js', | ||
+ | 'common.js', | ||
+ | )) ?> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
####出力 | ####出力 | ||
<syntaxhighlight lang="html5"> | <syntaxhighlight lang="html5"> | ||
− | <script type="text/javascript" src="/js/ | + | <script type="text/javascript" src="/theme/mytheme/js/jquery-3.3.1.min.js"></script> |
+ | <script type="text/javascript" src="/theme/mytheme/js/common.js"></script> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | ### | + | ### 応用1 |
+ | |||
+ | CDNを使用する場合、integrity属性、crossorigin属性を指定できる。 | ||
+ | |||
####コード | ####コード | ||
<syntaxhighlight lang="php"> | <syntaxhighlight lang="php"> | ||
− | + | <?php $this->BcBaser->js(array( | |
+ | 'https://code.jquery.com/jquery-3.3.1.js' | ||
+ | ), true, array( | ||
+ | 'integrity' => 'sha256-********************************', | ||
+ | 'crossorigin' => 'anonymous', | ||
+ | )) ?> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
####出力 | ####出力 | ||
<syntaxhighlight lang="html5"> | <syntaxhighlight lang="html5"> | ||
+ | <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-********************************" crossorigin="anonymous"></script> | ||
+ | </syntaxhighlight> | ||
+ | ### 応用2 | ||
+ | ####コード | ||
+ | <syntaxhighlight lang="php"> | ||
+ | <?php $this->BcBaser->js(array( | ||
+ | 'jquery-3.3.1.min.js', | ||
+ | 'common.js', | ||
+ | ),false ) ?> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | ####出力 | ||
+ | <syntaxhighlight lang="html5"> | ||
+ | (管理画面用CSSの出力後) | ||
+ | <script type="text/javascript" src="/theme/mytheme/js/jquery-3.3.1.min.js"></script><script type="text/javascript" src="/theme/mytheme/js/common.js"></script> | ||
+ | </syntaxhighlight> | ||
+ | |||
## 注 | ## 注 | ||
## 変更履歴 | ## 変更履歴 | ||
+ | |||
+ | ### 2018-06-15 | ||
+ | |||
+ | - CakePHPの仕様変更に伴い、関数の説明を大幅に変更 | ||
## ソースファイル | ## ソースファイル | ||
+ | |||
+ | [https://github.com/baserproject/basercms/blob/master/lib/Baser/View/Helper/BcBaserHelper.php](https://github.com/baserproject/basercms/blob/master/lib/Baser/View/Helper/BcBaserHelper.php) | ||
## 関連資料 | ## 関連資料 | ||
##類似の関数 | ##類似の関数 | ||
+ | |||
+ | [BcBaser->css](http://wiki.basercms.net/ver4/%E9%96%A2%E6%95%B0%E3%83%AA%E3%83%95%E3%82%A1%E3%83%AC%E3%83%B3%E3%82%B9/css) | ||
[[Category:関数リファレンスver4]] | [[Category:関数リファレンスver4]] |
2018年6月15日 (金) 12:42時点における版
目次
説明
JavaScriptの読み込みタグを出力する。
使い方
<?php $this->BcBaser->js( $url , [$inline] ); ?>
パラメータ
- (array)$url
- JavaScriptファイルまでのパス。拡張子は必要ない。キーを含まない値のみの配列として指定し、配列の順番の通りにJSが読み込まれる。
- 先頭にスラッシュをつけた場合は、baserCMSのルートからのパスとなる。スラッシュをつけず相対パスとした場合は、 /theme/{テーマ名}/js に該当ファイルが存在している場合、そのファイルへのパスとなる。
- (boolean)$inline
- 「true」を指定すると、関数を指定した箇所で一行ずつ改行して出力し、「false」を指定すると、管理画面用CSSの出力が終了してから改行を詰めて出力する。(初期値 : true)
戻り値
なし
用例
基本
コード
<?php $this->BcBaser->js(array( 'jquery-3.3.1.min.js', 'common.js', )) ?>
出力
<script type="text/javascript" src="/theme/mytheme/js/jquery-3.3.1.min.js"></script> <script type="text/javascript" src="/theme/mytheme/js/common.js"></script>
応用1
CDNを使用する場合、integrity属性、crossorigin属性を指定できる。
コード
<?php $this->BcBaser->js(array( 'https://code.jquery.com/jquery-3.3.1.js' ), true, array( 'integrity' => 'sha256-********************************', 'crossorigin' => 'anonymous', )) ?>
出力
<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-********************************" crossorigin="anonymous"></script>
応用2
コード
<?php $this->BcBaser->js(array( 'jquery-3.3.1.min.js', 'common.js', ),false ) ?>
出力
(管理画面用CSSの出力後)
<script type="text/javascript" src="/theme/mytheme/js/jquery-3.3.1.min.js"></script><script type="text/javascript" src="/theme/mytheme/js/common.js"></script>
注
変更履歴
2018-06-15
- CakePHPの仕様変更に伴い、関数の説明を大幅に変更
ソースファイル
https://github.com/baserproject/basercms/blob/master/lib/Baser/View/Helper/BcBaserHelper.php