Laravel 5.5 本地化和 CKEditor
Laravel 5.5 Localization and CKEditor
我想用ckeditor替换多个textarea(Content En和Content Ru),但它们都有相同的ID。怎么办,因为加载一个编辑器后就停止了。
表格:
{!! Form::open([ 'route' => 'portfolio.store', 'files' => 'true']) !!}
@foreach(config('translatable.locales') as $locale)
<div class="form-group">
<label for="translation[{{$locale}}][title]"><strong>Title ({{$locale}})</strong></label>
<input type="text" id="title"
name="translation[{{$locale}}][title]"
class="form-control"
value="{{ old('translation.'. $locale.'.title') }}">
</div>
<div class="form-group">
<label for="translation[{{$locale}}][content]"><strong>Content ({{$locale}})</strong></label>
<textarea name="translation[{{$locale}}][content]"
id="content"
class="form-control"
cols="30"
rows="10">{{ old('translation.'. $locale.'.content') }}</textarea>
</div>
@endforeach
<div class="form-group">
<label for="image"><strong>Image</strong></label>
<input type="file" id="image" name="image" class="form-control-file">
</div>
<br>
<input class="btn btn-success btn-lg btn-block" type="submit" value="Add Portfolio">
{!! Form::close() !!}
脚本:
<script>
CKEDITOR.replace( 'content' );
</script>
enter image description here
我可以从 CKEditor 的角度解释它是如何工作的。
请参阅:https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR.html#cfg-replaceClass and http://nightly.ckeditor.com/18-09-06-06-04/full/samples/old/replacebyclass.html。
CKEditor allwos 替换多个文本区域,前提是它们分配了一个特定的 CSS class(默认为 ckeditor
)。您需要做的就是在 HTML 文档的 header 部分附加 CKEditor 脚本,然后添加一堆 <textarea class="ckeditor" name="editor1"></textarea>
元素。他们应该 auto-changed 给编辑。
或者,您可以使用随机 id's
生成 textarea
元素,收集这些 id's
然后 运行 循环中的 replace
方法,使用 id
来自迭代步骤。
我想用ckeditor替换多个textarea(Content En和Content Ru),但它们都有相同的ID。怎么办,因为加载一个编辑器后就停止了。
表格:
{!! Form::open([ 'route' => 'portfolio.store', 'files' => 'true']) !!}
@foreach(config('translatable.locales') as $locale)
<div class="form-group">
<label for="translation[{{$locale}}][title]"><strong>Title ({{$locale}})</strong></label>
<input type="text" id="title"
name="translation[{{$locale}}][title]"
class="form-control"
value="{{ old('translation.'. $locale.'.title') }}">
</div>
<div class="form-group">
<label for="translation[{{$locale}}][content]"><strong>Content ({{$locale}})</strong></label>
<textarea name="translation[{{$locale}}][content]"
id="content"
class="form-control"
cols="30"
rows="10">{{ old('translation.'. $locale.'.content') }}</textarea>
</div>
@endforeach
<div class="form-group">
<label for="image"><strong>Image</strong></label>
<input type="file" id="image" name="image" class="form-control-file">
</div>
<br>
<input class="btn btn-success btn-lg btn-block" type="submit" value="Add Portfolio">
{!! Form::close() !!}
脚本:
<script>
CKEDITOR.replace( 'content' );
</script>
enter image description here
我可以从 CKEditor 的角度解释它是如何工作的。
请参阅:https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR.html#cfg-replaceClass and http://nightly.ckeditor.com/18-09-06-06-04/full/samples/old/replacebyclass.html。
CKEditor allwos 替换多个文本区域,前提是它们分配了一个特定的 CSS class(默认为 ckeditor
)。您需要做的就是在 HTML 文档的 header 部分附加 CKEditor 脚本,然后添加一堆 <textarea class="ckeditor" name="editor1"></textarea>
元素。他们应该 auto-changed 给编辑。
或者,您可以使用随机 id's
生成 textarea
元素,收集这些 id's
然后 运行 循环中的 replace
方法,使用 id
来自迭代步骤。