Forgot password
 Register account
original poster: hbghlyj

标记搜索词

[Copy link]

3211

Threads

7832

Posts

52

Reputation

Show all posts

original poster hbghlyj posted 2024-9-15 21:16
kuing 发表于 2024-9-15 13:01
刚才试了一下,结果就报错了,搞模板是真不会😔
哦,我明白了。在 MathJax 配置中有一个 {d},它被 Discuz 模板系统解释为常量 d

为了避免这种情况,可以用<!--{eval echo "{d}";}-->替换 {d}

673

Threads

110K

Posts

218

Reputation

Show all posts

kuing posted 2024-9-15 21:19
hbghlyj 发表于 2024-9-15 21:16
哦,我明白了。在 MathJax 配置中有一个 {d},它被 Discuz 模板系统解释为常量 d

为了避免这种情况,可 ...
那怎么解决?除了 {d},后面还有 {=},还有 {aligned} 等等这些全都不行吗?

3211

Threads

7832

Posts

52

Reputation

Show all posts

original poster hbghlyj posted 2024-9-15 21:24
kuing 发表于 2024-9-15 13:19
那怎么解决?除了 {d},后面还有 {=},还有 {aligned} 等等这些全都不行吗? ...
或者,像以前一样将它们保存到变量 $_G['setting']['seohead'] 中,只删除第一行window.MathJax = {,并在模板中使用变量 $_G['setting']['seohead']

673

Threads

110K

Posts

218

Reputation

Show all posts

kuing posted 2024-9-15 21:31
hbghlyj 发表于 2024-9-15 21:24
或者,像以前一样将它们保存到变量 $_G['setting']['seohead'] 中,只删除第一行,并在模板中使用变量 $_ ...
我不是说了吗
“其他头部信息”里除了 mathjax 还有其他东西,所以 ...

3211

Threads

7832

Posts

52

Reputation

Show all posts

original poster hbghlyj posted 2024-9-15 21:41
为了避免 Discuz 模板解析系统,我们可以使用 php 格式的模板
从 Discuz! X2.5 开始,模板文件支持 PHP 扩展名的格式,你可以创建例如 ./template/mytext/common/forum/discuz.php 文件

3211

Threads

7832

Posts

52

Reputation

Show all posts

original poster hbghlyj posted 2024-9-15 21:45
只需复制 /data/template/1_1_common_mathjax.tpl.php 将其重命名为 mathjax.php 并替换 mathjax.htm,您就可以更改里面的 php 代码

3211

Threads

7832

Posts

52

Reputation

Show all posts

original poster hbghlyj posted 2024-9-15 21:47

PHP 模板

只需重写 /data/template/1_1_common_mathjax.tpl.php 中导致错误的行,然后将其重命名为 mathjax.php 并将其放在与 mathjax.htm 相同的文件夹中。因为 PHP 和 HTM 模板文件同时存在时,会优先解析 PHP 模板文件

3211

Threads

7832

Posts

52

Reputation

Show all posts

original poster hbghlyj posted 2024-9-15 21:49
kuing 发表于 2024-9-15 13:19
还有 {aligned} 等等这些全都不行吗? ...
在 htm 模板中这是不行的,但在 php 模板中是可以的。因为 php 模板使用更严谨的语法。

3211

Threads

7832

Posts

52

Reputation

Show all posts

original poster hbghlyj posted 2024-9-15 21:54
我们应该尽量少用htm模板,多用php模板,这样可以避免在将htm模板转为php的过程中出错,而且php的语法更严格,调试起来也更方便,因为现在很多编辑器都有专门的php语法高亮器,而且有网站可以免费测试php代码,但htm模板只在Discuz内部使用,不能在任何地方使用

673

Threads

110K

Posts

218

Reputation

Show all posts

kuing posted 2024-9-15 22:04
hbghlyj 发表于 2024-9-15 21:47
只需重写 /data/template/1_1_common_mathjax.tpl.php 中导致错误的行,然后将其重命名为 mathjax.php 并 ...
以下就是 /data/template/1_1_common_mathjax.tpl.php 的内容
  1. <?php if(!defined('IN_DISCUZ')) exit('Access Denied'); ?>
  2. <script>
  3. window.MathJax = {
  4. <?php if(!empty($_GET['highlight'])) { ?>
  5.   startup: {
  6.     typeset: false
  7.   },
  8. <?php } ?>
  9.   tex: {
  10.     inlineMath: [ ['$','$'], ['`','`'], ["\\(","\\)"] ],
  11.     processEscapes: true,
  12.     tags: "ams",
  13.     macros: {
  14.       Bbb: '\\mathbb',
  15.       riff: '\\implies',
  16.       liff: '\\impliedby',
  17.       abs: ['\\left\\lvert #1\\right\\rvert', 1],
  18.       rmd: '\\mathop{}\\!\\mathrm<?php echo d;?>',
  19.       vv: '\\overrightarrow',
  20.       sslash: '\\mathrel{/\\mkern-5mu/}',
  21.       px: '\\mathrel{/\\mkern-5mu/}',
  22.       pqd: '\\stackrel{\\smash[b]{/\\!/}}{\\raise-.3ex{=}}',
  23.       veps: '\\varepsilon',
  24.       du: '^\\circ',
  25.       bsb: '\\boldsymbol',
  26.       bm: '\\boldsymbol',
  27.       kongji: '\\varnothing',
  28.       buji: '\\complement',
  29.       S: ['S_{\\triangle #1}', 1],
  30.       led: '\\left\\{\\begin<?php echo aligned;?>',
  31.       endled: '\\end<?php echo aligned;?>\\right.',
  32.       edr: '\\left.\\begin<?php echo aligned;?>',
  33.       endedr: '\\end<?php echo aligned;?>\\right\\}',
  34.       an: '\\{a_n\\}',
  35.       bn: '\\{b_n\\}',
  36.       cn: '\\{c_n\\}',
  37.       xn: '\\{x_n\\}',
  38.       Sn: '\\{S_n\\}',
  39.       inR: '\\in\\Bbb R',
  40.       inN: '\\in\\Bbb N',
  41.       inZ: '\\in\\Bbb Z',
  42.       inC: '\\in\\Bbb C',
  43.       inQ: '\\in\\Bbb Q',
  44.       Rtt: '\\text<?php echo Rt;?>\\triangle',
  45.       LHS: '\\text<?php echo LHS;?>',
  46.       RHS: '\\text<?php echo RHS;?>',
  47.       arccot: '\\operatorname<?php echo arccot;?>',
  48.       arcsinh: '\\operatorname<?php echo arcsinh;?>',
  49.       arccosh: '\\operatorname<?php echo arccosh;?>',
  50.       arctanh: '\\operatorname<?php echo arctanh;?>',
  51.       arccoth: '\\operatorname<?php echo arccoth;?>',
  52.     },
  53.     autoload: {
  54.       color: [],
  55.       colorv2: ['color']
  56.     },
  57.     packages: {'[+]': ['noerrors','mathtools','xypic']}
  58.   },
  59.   options: {
  60.     ignoreHtmlClass: 'blockcode',
  61.     menuOptions: {
  62.       settings: {
  63.         zoom: "DoubleClick"
  64.       }
  65.     },
  66.     processHtmlClass: 'tex2jax_process',
  67.     renderActions: {
  68.       assistiveMml: []
  69.     }
  70.   },
  71.   //chtml: {
  72.   //  scale: 0.9
  73.   //},
  74.   loader: {
  75.     load: ['[tex]/noerrors','[tex]/mathtools','[custom]/xypic.js'],
  76.     //paths: {custom: '//cdn.jsdelivr.net/gh/sonoisa/XyJax-v3@3.0.1/build'}
  77.     paths: {custom: 'kk'}
  78.   },
  79.   svg: {
  80.     scale: 0.9,
  81.     fontCache: 'global'
  82.   }
  83. };
  84. </script>
  85. <!--<script src="//polyfill.io/v3/polyfill.min.js?features=es6" type="text/javascript"></script>-->
  86. <!--<script src="//cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js" type="text/javascript"></script>-->
  87. <!--<script src="//cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js" type="text/javascript"></script>-->
  88. <script src="mathjax3/es5/tex-svg.js" type="text/javascript"></script>
  89. <!--<script src="mathjax3/es5/tex-chtml.js" type="text/javascript"></script>-->
  90. <!--<script src="//unpkg.com/mathjax@3.2.2/es5/tex-svg.js" type="text/javascript"></script>-->
  91. <!--<script src="//unpkg.com/mathjax@3.2.2/es5/tex-chtml.js" type="text/javascript"></script>-->
  92. <!--<script src="//cdn.bootcdn.net/ajax/libs/mathjax/3.2.2/es5/tex-svg.min.js" type="text/javascript"></script>-->
  93. <!--<script src="//cdn.bootcdn.net/ajax/libs/mathjax/3.2.2/es5/tex-chtml.js" type="text/javascript"></script>-->
Copy the Code

3211

Threads

7832

Posts

52

Reputation

Show all posts

original poster hbghlyj posted 2024-9-15 22:07
kuing 发表于 2024-9-15 14:04
以下就是 /data/template/1_1_common_mathjax.tpl.php 的内容
是的,我们可以将 <?php echo d;?> 恢复为 {d}

673

Threads

110K

Posts

218

Reputation

Show all posts

kuing posted 2024-9-15 22:12
hbghlyj 发表于 2024-9-15 22:07
是的,我们可以将 <?php echo d;?> 恢复为 {d}
前面的
  1. <?php if(!empty($_GET['highlight'])) { ?>
  2.   startup: {
  3.     typeset: false
  4.   },
  5. <?php } ?>
Copy the Code
这里的语法是OK的吗?

3211

Threads

7832

Posts

52

Reputation

Show all posts

original poster hbghlyj posted 2024-9-15 22:15
kuing 发表于 2024-9-15 14:12
前面的

这里的语法是OK的吗?
您走在正确的轨道上。PHP 关闭标签不会停止脚本,它只是告诉 php 要解析什么,不要解析什么。
您可以在文件中根据需要打开和关闭任意数量的 php 标签,只要标签内的 PHP 有效即可。
您可以通过关闭 php 标签来打印 HTML。php 解析器不会解析 html,但它知道它在那里。

3211

Threads

7832

Posts

52

Reputation

Show all posts

original poster hbghlyj posted 2024-9-15 22:24
kuing 发表于 2024-9-15 14:12
前面的

这里的语法是OK的吗?
甚至可以在 for 循环中使用:
例如代码
  1. <?php  
  2. for ($x = 0; $x <= 10; $x++) {
  3.   echo 'The number is: $x <br>';
  4. }
  5. ?>  
Copy the Code
和代码
  1. <?php  
  2. for ($x = 0; $x <= 10; $x++) {
  3. ?>
  4. The number is: $x <br>
  5. <?php
  6. }
  7. ?>
Copy the Code
输出相同:
  1. The number is: $x
  2. The number is: $x
  3. The number is: $x
  4. The number is: $x
  5. The number is: $x
  6. The number is: $x
  7. The number is: $x
  8. The number is: $x
  9. The number is: $x
  10. The number is: $x
  11. The number is: $x
Copy the Code

Comment

哦😮  posted 2024-9-15 22:28

3211

Threads

7832

Posts

52

Reputation

Show all posts

original poster hbghlyj posted 2024-9-15 22:27
kuing 发表于 2024-9-15 14:12
前面的

这里的语法是OK的吗?
php 的其他有趣功能:
__halt_compiler中断编译器的执行。常用于在 PHP 脚本内嵌入数据,类似于安装文件。

673

Threads

110K

Posts

218

Reputation

Show all posts

kuing posted 2024-9-15 22:54
hbghlyj 发表于 2024-9-15 21:47
只需重写 /data/template/1_1_common_mathjax.tpl.php 中导致错误的行,然后将其重命名为 mathjax.php 并 ...
仍然报错,唉……
不玩了……都影响到他人使用了:forum.php?mod=viewthread&tid=12724

3211

Threads

7832

Posts

52

Reputation

Show all posts

original poster hbghlyj posted 2024-9-15 23:06
kuing 发表于 2024-9-15 14:54
仍然报错,唉……
不玩了……都影响到他人使用了:https://kuing.cjhb.site/forum.php?mod=view ...
建议在 GitHub Codespace 上测试,它将被部署到 github.dev 而不是这个网站,这样我们就可以在发布之前测试代码,而不会影响访问的用户

673

Threads

110K

Posts

218

Reputation

Show all posts

kuing posted 2024-9-15 23:08
hbghlyj 发表于 2024-9-15 23:06
建议在 GitHub Codespace 上测试,它将被部署到 github.dev 而不是这个网站,这样我们就可以在发布之前测 ...
我哪会那么多

Comment

本地测试更快捷、更安全:
无需上传,节省时间;
保持服务器端不变,不会影响用户访问🙂  posted 2024-9-15 23:35

3211

Threads

7832

Posts

52

Reputation

Show all posts

original poster hbghlyj posted 2024-9-15 23:30
本地搭建discuz是将Discuz!论坛系统部署在本地计算机上,通过搭建本地服务器环境,模拟线上环境进行开发和测试。

优势:
  • 离线开发和测试:本地搭建discuz可以在没有网络连接的情况下进行开发和测试,提高开发效率。
  • 隔离环境:本地搭建discuz可以在不影响线上环境的情况下进行开发和测试,避免潜在的线上风险。
  • 学习和研究:本地搭建discuz可以供开发者学习和研究Discuz!论坛系统的内部机制和开发技术。

3211

Threads

7832

Posts

52

Reputation

Show all posts

original poster hbghlyj posted 2024-9-15 23:39

设置本地开发服务器

设置本地服务器很容易,例如监听端口 8080,可以在浏览器中输入 localhost:8080 来访问本地服务器
single-page-application_rollup_web-dev-server[1].png

Quick Reply

Advanced Mode
B Color Image Link Quote Code Smilies
You have to log in before you can reply Login | Register account

$\LaTeX$ formula tutorial

Mobile version

2025-7-20 05:49 GMT+8

Powered by Discuz!

Processed in 0.017205 seconds, 28 queries